diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 5ff6309..0000000 --- a/.gitignore +++ /dev/null @@ -1,38 +0,0 @@ -target/ -!.mvn/wrapper/maven-wrapper.jar -!**/src/main/**/target/ -!**/src/test/**/target/ - -### IntelliJ IDEA ### -.idea/modules.xml -.idea/jarRepositories.xml -.idea/compiler.xml -.idea/libraries/ -*.iws -*.iml -*.ipr - -### Eclipse ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ -build/ -!**/src/main/**/build/ -!**/src/test/**/build/ - -### VS Code ### -.vscode/ - -### Mac OS ### -.DS_Store \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index 2b63946..0000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/.gitignore b/LightCity-AmirHosseinZh/.idea/.gitignore similarity index 100% rename from .idea/.gitignore rename to LightCity-AmirHosseinZh/.idea/.gitignore diff --git a/LightCity-AmirHosseinZh/.idea/compiler.xml b/LightCity-AmirHosseinZh/.idea/compiler.xml new file mode 100644 index 0000000..9c435a1 --- /dev/null +++ b/LightCity-AmirHosseinZh/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/LightCity-AmirHosseinZh/.idea/encodings.xml similarity index 100% rename from .idea/encodings.xml rename to LightCity-AmirHosseinZh/.idea/encodings.xml diff --git a/LightCity-AmirHosseinZh/.idea/jarRepositories.xml b/LightCity-AmirHosseinZh/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/LightCity-AmirHosseinZh/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/LightCity-AmirHosseinZh/.idea/misc.xml similarity index 73% rename from .idea/misc.xml rename to LightCity-AmirHosseinZh/.idea/misc.xml index 0a13117..44185bb 100644 --- a/.idea/misc.xml +++ b/LightCity-AmirHosseinZh/.idea/misc.xml @@ -8,7 +8,5 @@ - - - + \ No newline at end of file diff --git a/LightCity-AmirHosseinZh/README.md b/LightCity-AmirHosseinZh/README.md new file mode 100644 index 0000000..b79bccf --- /dev/null +++ b/LightCity-AmirHosseinZh/README.md @@ -0,0 +1,3 @@ +Hossein GHolami: DataBase from sql +AmirHossein Ziarati: Impliment industries +Kiarash EbrahimNezhad: CLI menu(Step 2,5) diff --git a/pom.xml b/LightCity-AmirHosseinZh/pom.xml similarity index 70% rename from pom.xml rename to LightCity-AmirHosseinZh/pom.xml index 8e8bcb0..ad15b26 100644 --- a/pom.xml +++ b/LightCity-AmirHosseinZh/pom.xml @@ -24,4 +24,16 @@ test + + + + org.apache.maven.plugins + maven-compiler-plugin + + 19 + 19 + + + + diff --git a/src/main/java/org/example/App.java b/LightCity-AmirHosseinZh/src/main/java/org/example/App.java similarity index 100% rename from src/main/java/org/example/App.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/App.java diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/Database.java b/LightCity-AmirHosseinZh/src/main/java/org/example/Database.java new file mode 100644 index 0000000..2e7778b --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/Database.java @@ -0,0 +1,261 @@ +package org.example; + +import org.example.models.*; +import com.sun.tools.javac.Main; +import org.example.models.Character; +import org.example.models.Property; +import org.example.models.User; +import org.example.defualtSystem.*; + +import javax.xml.crypto.Data; + +import org.example.Database; + +import java.sql.*; +import java.util.ArrayList; + +public class Database { + + + static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + static final String DB_URL = "jdbc:mysql://localhost:3306/lightCity"; + + // Database credentials + static final String USER = "root"; + static final String PASS = "hossein1383"; + + public static ArrayList characters = new ArrayList<>(); + private static Connection conn; + + public Database() { + try { + Class.forName(JDBC_DRIVER); + conn = DriverManager.getConnection(DB_URL, USER, PASS); + System.out.println("Connecting to database..."); + } catch (Exception exp) { + System.out.println("Database Exception : \n" + exp.toString()); + System.exit(0); + } + } + + public static void updateCharacter(String status, Character character) { + String updateQuery = ""; + switch (status) { + case "location": + updateQuery = "UPDATE characters SET location = ? WHERE username = ?"; + break; + case "job": + updateQuery = "UPDATE characters SET job = ? WHERE username = ?"; + break; + case "life": + updateQuery = "UPDATE characters SET life = ? WHERE username = ?"; + break; + case "money": + updateQuery = "UPDATE characters SET money = ? WHERE username = ?"; + break; + default: + System.out.println("Invalid status: " + status); + return; + } + + try (Connection connection = DriverManager.getConnection(DB_URL, USER, PASS); + PreparedStatement statement = connection.prepareStatement(updateQuery)) { + + switch (status) { + case "location": + String location = character.getInPosition() != null ? + character.getInPosition().getCoordinate()[0] + "," + character.getInPosition().getCoordinate()[1] : + "null"; + statement.setString(1, location); + break; + case "job": + statement.setString(1, character.getJob().getTitle()); + break; + case "life": + Life life = character.getLife(); + String lifeDetails = life.getFood() + "," + life.getSleep() + "," + life.getWater(); + statement.setString(1, lifeDetails); + break; + case "money": + BankAccount bankAccount = character.getAccount(); + statement.setFloat(1, bankAccount.getMoney()); + break; + } + + statement.setString(2, character.getUserInfo().getUsername()); + statement.executeUpdate(); + + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + + // Tables + + /** + * Users + */ + + private void createTables() { +// query example + String query = "CREATE TABLE IF NOT EXISTS Users (username varchar(255) primary key ,password varchar(255));" + + "CREATE TABLE IF NOT EXISTS ...."; + try { + Statement stmt = conn.createStatement(); + if (stmt.execute(query)) { + + } else + System.out.println("An error accord during operation"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + static String userName; + static String passWord; + + public static User loginGame(User user) { + + try { + Statement stmt = conn.createStatement(); + String query = "SELECT * FROM lightCity"; + ResultSet res = stmt.executeQuery(query); + while (res.next()) { + userName = res.getString(1); + passWord = res.getString(2); + if (user.getUsername().equals(userName) && user.getPassword().equals(passWord)) { + return user; + } + } + } catch (Exception exception) { + } + return null; + } + + public static boolean notNull(User user) { + try { + Statement statement = conn.createStatement(); + ResultSet res = statement.executeQuery("SELECT * FROM users"); + if (res.next()) { + return false; + } else + return true; + } catch (Exception e) { + } + return false; + } + + public static User registerGame(User user) { + boolean isNotNull = notNull(user); + if (!isNotNull) { + try { + Statement statement = conn.createStatement(); + String query = String.format("INSERT INTO lightCity(username,password) VALUES(%s,%s)", user.getUsername(), user.getPassword()); + } catch (Exception e) { + } + } + return null; + } + + public static void saveProperties(Property property) { + String query = "INSERT INTO properties(width , height,coordinate1,coordinate2,owner) VALUES (?,?,?,?,?)"; + try { + PreparedStatement preparedStatement = conn.prepareStatement(query); + float width = property.getScales()[0]; + float height = property.getScales()[1]; + float xCoordinate = property.getCoordinate()[0]; + float yCoordinate = property.getScales()[1]; + preparedStatement.setFloat(1, width); + preparedStatement.setFloat(2, height); + preparedStatement.setFloat(3, xCoordinate); + preparedStatement.setFloat(4, yCoordinate); + if (property.getOwner() == null) { + preparedStatement.setString(5, "defaultOwner"); + } else + preparedStatement.setString(5, property.getOwner().toString()); + preparedStatement.executeUpdate(); + } catch (Exception e) { + + } + + } + + public static void saveCharacter(Character character) { + String insertQuery = "INSERT INTO `characters`(`username`, `password`, `money`, `life`, `job`, `location`) VALUES (?,?,?,?,?,?)"; + + try (Connection connection = DriverManager.getConnection(DB_URL, USER, PASS); + PreparedStatement statement = connection.prepareStatement(insertQuery)) { + + String username = character.getUserInfo().getUsername(); + String password = character.getUserInfo().getPassword(); + String life = character.getLife().getFood() + "," + character.getLife().getSleep() + "," + character.getLife().getWater(); + String jobTitle = ""; + if (character.getJob() == null) { + jobTitle = "null"; + } else { + jobTitle = character.getJob().getTitle(); + } + String inLocation = " "; + + if (character.getInPosition() == null) { + inLocation = "null"; + } else { + inLocation = character.getInPosition().getCoordinate()[0] + "," + character.getInPosition().getCoordinate()[1]; + } + + statement.setString(1, username); + statement.setString(2, password); + statement.setFloat(3, character.getAccount().getMoney()); + statement.setString(4, life); + statement.setString(5, jobTitle); + statement.setString(6, inLocation); + + statement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + public static ArrayList getProperties() { + ArrayList getPropertiesList = new ArrayList<>(); + try { + Statement statement = conn.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT * FROM properties"); + while (resultSet.next()) { + float width = resultSet.getFloat("width"); + float height = resultSet.getFloat("height"); + float xCoordinate = resultSet.getFloat("xCoordinate"); + float yCoordinate = resultSet.getFloat("yCoordinate"); + Property property = new Property(new float[]{width, height}, new float[]{xCoordinate, yCoordinate}, null); + getPropertiesList.add(property); + } + return getPropertiesList; + } catch (Exception e) { + + } + return getPropertiesList; + } + + public static void createBankAccount(BankAccount bankAccount) { + String insertQuery = "INSERT INTO `bank-account`(`username`, `password`, `money`, `last`) VALUES (?,?,?,?)"; + + try (Connection connection = DriverManager.getConnection(DB_URL, USER, PASS); + PreparedStatement statement = connection.prepareStatement(insertQuery)) { + + String username = bankAccount.getOwner(); + String password = bankAccount.getPassword(); + float money = bankAccount.getMoney(); + String last = bankAccount.getLastChange().toString(); + statement.setString(1, username); + statement.setString(2, password); + statement.setFloat(3, money); + statement.setString(4, last); + statement.executeUpdate(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/Game.java b/LightCity-AmirHosseinZh/src/main/java/org/example/Game.java new file mode 100644 index 0000000..7785eef --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/Game.java @@ -0,0 +1,51 @@ +package org.example; + +import org.example.interfaces.GameInterface; +import org.example.models.Character; +import org.example.models.City; +import org.example.models.User; + +import java.util.ArrayList; +import java.util.Scanner; + +public class Game implements GameInterface { + +// Check Data from Database or file to see There is city or not + private City city; + @Override + public void continueGame(User user) { + if (user != null){ + City city = new City(); + } + + } + +/** Create new city and Generate new Character + * @param user : User information contain username, password + * */ + @Override + public void startGame(User user) { + + generateNewCity(); + city.joinCharacter(user); + //data base;save and send data; + + + + } + + /** + * @param ip Server ip address / example : 127.0.0.1 + * @param port Server open port for specific ip address + * */ + @Override + public void joinServer(String ip, int port) { + + } + + @Override + public void generateNewCity() { + city = new City(); + } + +} diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/Menu.java b/LightCity-AmirHosseinZh/src/main/java/org/example/Menu.java new file mode 100644 index 0000000..cbd43de --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/Menu.java @@ -0,0 +1,197 @@ +package org.example; + +import org.example.models.User; + +import java.util.Scanner; + +public class Menu { + private static Game game = new Game(); + private static Scanner scanner = new Scanner(System.in); + + public static void showMenu() { + while (true) { + mainMenu(); + String next = scanner.next(); + if (next.equals("1")) { + game.continueGame(loginMenu()); + } else if (next.equals("2")) { + game.startGame(loginMenu()); + } else if (next.equals("3")) { + joinServer(); + } else if (next.equals("4")) + System.exit(0); + } + } + + public static void mainMenu() { +// show menu : sout () + System.out.println("****************************"); + System.out.println("*** 1-Continue Game ***"); + System.out.println("*** 2-Start Game ***"); + System.out.println("*** 3-Join Server ***"); + System.out.println("*** 4-Exit ***"); + System.out.println("****************************"); + + } + + public static void userMenu()//print option for user + { + System.out.println("****************************"); + System.out.println("*** 1-Go to ***"); + System.out.println("*** 2-Process Location ***"); + System.out.println("*** 3-Dashboard ***"); + System.out.println("*** 4-Life ***"); + System.out.println("*** 5-Exit ***"); + System.out.println("****************************"); + } + + public static void showUserMenu (User user) { + userMenu(); + String next = scanner.next(); + switch (next) { + case "1": { + System.out.println("** Enter location (1 or 2) **"); + System.out.println("** a. Location ID **"); + System.out.println("** b. Industry Title **"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.out.print("Enter Your Location ID : "); + String LocationId = scanner.next(); + //complete this part + } else if (nextGoTo.equals("b")) { + System.out.print("Enter Your Industry Title : "); + String IndustryTitle = scanner.next(); + //complete this part + } + } + case "2": { + System.out.println("** Show Detail (1 or 2) **"); + System.out.println("** a. Show where is character : Property detail {position , title,…} **"); + System.out.println("** b. Show options according to Industry and Property ownership **"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + //kia(level of user) + //complete this part + } else if (nextGoTo.equals("b")) { + //option of user industry + //complete this part + } + } + case "3": { + System.out.println("a. My Job"); + System.out.println("b. Properties"); + System.out.println("c. Economy"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.out.println("i. Find Job"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //find job + } + } else if (nextGoTo.equals("b")) { + System.out.println("i. Show Properties"); + System.out.println("ii. Sell"); + System.out.println("iii. Management"); + System.out.println("iv. Found Industry"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //show prprty + } else if (nextGoToOptions.equals("ii")) { + //sell + } else if (nextGoToOptions.equals("iii")) { + //management + } else if (nextGoToOptions.equals("iv")) { + //found indstry + } + } else if (nextGoTo.equals("c")) { + System.out.println("i. Show Incomes"); + System.out.println("ii. Show Job Detail"); + System.out.println("iii. How Can Grow Up"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //show incomes + } else if (nextGoToOptions.equals("ii")) { + //show job detail + } else if (nextGoToOptions.equals("iii")) { + //H C Grow Up + } + } + } + case ("4"): { + System.out.println("a. Life Detail"); + System.out.println("b. Sleep Function"); + System.out.println("c. Eat Function"); + System.out.println("d. Show (Food , Water , Sleep) Percent"); + } + case ("5"): { + System.out.println("a. Are You Sure?"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.exit(0); + } + } + } + } + + public static User loginMenu() { + boolean b = true; + while (b) { + Scanner input = new Scanner(System.in); + System.out.print("** Enter your username : "); + String username = input.nextLine(); + System.out.print("** Enter your password: "); + String password = input.nextLine(); + User user = new User(username, password); + if (Database.loginGame(user) != null) { + return user; + } else { + System.out.println("1. logIn"); + System.out.println("2. signUp"); + System.out.println("3. back"); + String temp = input.nextLine(); + switch (temp) { + case "1" -> game.continueGame(loginMenu()); + case "2" -> game.startGame(registerMenu()); + case "3" -> b = false; + } + } + } + return null; + } + + private static void joinServer() { + System.out.print("Enter Server Ip Address :"); + String ip = scanner.next(); + System.out.print("Enter Server Port :"); + int port = scanner.nextInt(); + game.joinServer(ip, port); + } + + public static User registerMenu() { + boolean b = true; + while (b){ + Scanner input = new Scanner(System.in); + System.out.print("** Enter your username : "); + String username = input.nextLine(); + System.out.print("** Enter your password: "); + String password = input.nextLine(); + User user = new User(username, password); + if (Database.loginGame(user) != null) { + return user; + } else { + System.out.println("1. logIn"); + System.out.println("2. back"); + } + String next = input.nextLine(); + switch (next) { + case "1" -> loginMenu(); + case "2" -> b = false; + } + } + return null; + } + + public static void main(String[] args) { + showMenu(); + } +} diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Bank.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Bank.java new file mode 100644 index 0000000..d0d2e44 --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Bank.java @@ -0,0 +1,44 @@ +package org.example.defualtSystem; + +import org.example.interfaces.BankInterface; +import org.example.models.*; +import org.example.models.Character; + +import java.util.ArrayList; +import java.util.Date; + +public class Bank extends Industry implements BankInterface { + + private static final int MAX_EMPLOYEE_COUNT = 5; + private static final float BASE_EMP_SALARY = 0.5f; + private ArrayList accounts = new ArrayList(); + + private Manager manager = null; + + public static BankTurnover turnover; + + public Bank(Property property,Character root) { + super("Bank",property,root,100.0f); + turnover = new BankTurnover(); + } + + public BankAccount newAccount(String username,String password){ + BankAccount bankAccount = new BankAccount(username,password,10,new Date()); + accounts.add(bankAccount); + return bankAccount; + } + public boolean registerAsEmp(Character character){ + if(employees.size() >= MAX_EMPLOYEE_COUNT)return false; + Employee employee = new Employee(character.getUserInfo().getUsername(),this,BASE_EMP_SALARY,character.getAccount()); + employees.add(employee); + return true; + } + + + public String bankDetail(Character character){ + if(character.getUserInfo().getUsername().equals(manager.getUsername())){ + return ""; + } + return "Only Manager can see Bank detail"; + } +} diff --git a/src/main/java/org/example/defualtSystem/BankTurnover.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/BankTurnover.java similarity index 100% rename from src/main/java/org/example/defualtSystem/BankTurnover.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/BankTurnover.java diff --git a/src/main/java/org/example/defualtSystem/FastFoodShop.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/FastFoodShop.java similarity index 100% rename from src/main/java/org/example/defualtSystem/FastFoodShop.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/FastFoodShop.java diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Life.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Life.java new file mode 100644 index 0000000..024e718 --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Life.java @@ -0,0 +1,96 @@ +package org.example.defualtSystem; + +import org.example.models.Food; +import org.example.models.Liquid; + +public class Life { + private float food; + private float water; + private float sleep; + + public Life(){ + food = 100.0f; + water=100.0f; + sleep=100.0f; + } + + public Life(float food, float water, float sleep) { + this.food = food; + this.water = water; + this.sleep = sleep; + startConsuming(); + } + + public float getFood() { + return food; + } + + public float getWater() { + return water; + } + + public float getSleep() { + return sleep; + } + + + public void foodConsumption(Food product){ + if(product.available){ + water+=product.getWater(); + food +=product.getFood(); + } + } + + public void liquidConsumption(Liquid product){ + if(product.available){ + water+=product.getLiquid(); + } + } + + + public void startConsuming() { + Thread thread = new Thread(() -> { + while (true) { + consumeFood(0.4f); + consumeWater(0.8f); + consumeSleep(0.7f); + + try { + Thread.sleep(60000); // wait for 1 minute + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + + thread.start(); + } + + private synchronized void consumeFood(float amount) { + if (food >= amount) { + food -= amount; + } else { + System.out.println("Not enough food!"); + } + } + + private synchronized void consumeWater(float amount) { + if (water >= amount) { + water -= amount; + } else { + System.out.println("Not enough water!"); + } + } + + private synchronized void consumeSleep(float amount) { + if (sleep >= amount) { + sleep -= amount; + } else { + System.out.println("Not enough sleep!"); + } + } + + public void setSleep(float sleep) { + this.sleep = sleep; + } +} diff --git a/src/main/java/org/example/defualtSystem/Municipality.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Municipality.java similarity index 100% rename from src/main/java/org/example/defualtSystem/Municipality.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/Municipality.java diff --git a/src/main/java/org/example/defualtSystem/StockMarket.java b/LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/StockMarket.java similarity index 100% rename from src/main/java/org/example/defualtSystem/StockMarket.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/defualtSystem/StockMarket.java diff --git a/src/main/java/org/example/enumerations/Gender.java b/LightCity-AmirHosseinZh/src/main/java/org/example/enumerations/Gender.java similarity index 100% rename from src/main/java/org/example/enumerations/Gender.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/enumerations/Gender.java diff --git a/src/main/java/org/example/interfaces/BankInterface.java b/LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/BankInterface.java similarity index 100% rename from src/main/java/org/example/interfaces/BankInterface.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/BankInterface.java diff --git a/src/main/java/org/example/interfaces/CharacterInterface.java b/LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/CharacterInterface.java similarity index 100% rename from src/main/java/org/example/interfaces/CharacterInterface.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/CharacterInterface.java diff --git a/src/main/java/org/example/interfaces/CityInterface.java b/LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/CityInterface.java similarity index 100% rename from src/main/java/org/example/interfaces/CityInterface.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/CityInterface.java diff --git a/src/main/java/org/example/interfaces/GameInterface.java b/LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/GameInterface.java similarity index 100% rename from src/main/java/org/example/interfaces/GameInterface.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/GameInterface.java diff --git a/src/main/java/org/example/interfaces/MunicipalityInterface.java b/LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/MunicipalityInterface.java similarity index 100% rename from src/main/java/org/example/interfaces/MunicipalityInterface.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/interfaces/MunicipalityInterface.java diff --git a/src/main/java/org/example/models/BankAccount.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/BankAccount.java similarity index 100% rename from src/main/java/org/example/models/BankAccount.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/BankAccount.java diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/models/Character.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Character.java new file mode 100644 index 0000000..289c2b3 --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Character.java @@ -0,0 +1,80 @@ +package org.example.models; + +import org.example.defualtSystem.Life; +import org.example.interfaces.CharacterInterface; + +import java.util.ArrayList; + +public class Character implements CharacterInterface { + private User userInfo; + private BankAccount account; + private Life life; + + private Job job; + private ArrayList properties; + + private Property inPosition; + + public Character(User userInfo, BankAccount account, Life life, Job job, ArrayList properties, Property inPosition) { + this.userInfo = userInfo; + this.account = account; + this.life = life; + this.job = job; + this.properties = properties; + this.inPosition = inPosition; + } + + public User getUserInfo() { + return userInfo; + } + + public void setUserInfo(User userInfo) { + this.userInfo = userInfo; + } + + public BankAccount getAccount() { + return account; + } + + public void setAccount(BankAccount account) { + this.account = account; + } + + public Life getLife() { + return life; + } + + public void setLife(Life life) { + this.life = life; + } + + public Job getJob() { + return job; + } + + public void setJob(Job job) { + this.job = job; + } + + public void gotToLocation(Property destination){ + if(destination==null)return; + inPosition = destination; + } + + public ArrayList getProperties() { + return properties; + } + + public void setProperties(ArrayList properties) { + this.properties = properties; + } + + @Override + public void positionProcessing() { + + } + + public Property getInPosition() { + return inPosition; + } +} diff --git a/LightCity-AmirHosseinZh/src/main/java/org/example/models/City.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/City.java new file mode 100644 index 0000000..34b59b6 --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/java/org/example/models/City.java @@ -0,0 +1,245 @@ +package org.example.models; + +import org.example.Database; +import org.example.defualtSystem.Bank; +import org.example.defualtSystem.Life; +import org.example.defualtSystem.Municipality; +import org.example.defualtSystem.StockMarket; +import org.example.interfaces.CityInterface; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Scanner; + +public class City implements CityInterface { + private final ArrayList characters; + private final Bank bankSystem; + private final Municipality municipality; + + private final StockMarket stockMarket; + + private Character root; + + public City() { + characters = new ArrayList<>(); + municipality = new Municipality(); +// Get Bank Property from municipality + bankSystem = new Bank(new Property(new float[]{12, 32}, new float[]{42, 32}, root), root); + stockMarket = new StockMarket(); + stockMarket.startMarketSimulation(); + } + /** + * Begin Game function generate a new thread for each character , DO NOT CHANGE THIS FUNCTION STRUCTURE , + * + * */ + @Override + public void joinCharacter(User userinfo) { + try { + BankAccount newAccount = bankSystem.newAccount(userinfo.getUsername(), userinfo.getPassword()); + Database.createBankAccount(newAccount); + Character character = new Character(userinfo, newAccount, new Life(), null, null, null); + characters.add(character); + Database.saveCharacter(character); + beginGame(character); + } + catch (Exception e){ + System.out.println("user not found!"); + } + } + + private void beginGame(Character character) { + } + + @Override + public void getCityDetail() { + String players = Arrays.toString(characters.toArray()); + } + + + /** + * Begin Game function generate a new thread for each character , DO NOT CHANGE THIS FUNCTION STRUCTURE , + */ +// public void beginGame(Character character) { +//// using thread to save details for prevent from unsaved change due to system shutdown +// Thread savingLife = new Thread(() -> { +// while (true) { +// Database.updateCharacter("life", character); +// try { +// Thread.sleep(60000 * 2); // save each 2 minute +// } catch (InterruptedException e) { +// e.printStackTrace(); +// } +// } +// }); +// savingLife.start(); +// +// Thread thread = new Thread(() -> { +// try { +// Scanner scanner = new Scanner(System.in); +// System.out.println("panel menu"); +// System.out.println("1. go to place "); +// System.out.println("2. process location"); +// System.out.println("3. dashboard "); +// System.out.println("4. life "); +// System.out.println("5. exit "); +// System.out.println("**************************************"); +// System.out.println("enter your command : "); +// while (true) { +// switch (scanner.next()) { +// case "1" -> GoTo(character); +// case "2" -> Process_location(character); +// case "3" -> Dashboard(character); +// case "4" -> Life(character); +// case "5" -> { +// System.out.println("are you sure?[yes/no]"); +// if (scanner.next().equals("yes")) { +// System.exit(1); +// } else { +// beginGame(character); +// } +// } +// } +// } +// } catch (Exception e) { +// throw new RuntimeException(e); +// } +// }); +// thread.start(); +// } + public void Life(Character character) { + Scanner scanner = new Scanner(System.in); + System.out.println("life menu"); + System.out.println("* life detail [1] *"); + System.out.println("* sleep option [2] *"); + System.out.println("* eat option [3] *"); + System.out.println("* back [4] *"); + System.out.println("enter number: "); + switch (scanner.next()) { + case "1" -> Life_Detail(character); + case "2" -> Sleep(character); + case "3" -> Eat(character); + case "4" -> beginGame(character); + } + } +// public void GoTo(Character character) { +// System.out.println("***************************************"); +// System.out.println("**** go to place ****"); +// System.out.println("***************************************"); +// municipality.showProperties(character, Database.LoadProperties()); +// System.out.println("Tip: if you want travel by coordinate write in this order :(divide it by comma) X,Y"); +// +// Scanner MyPlace = new Scanner(System.in); +// String place = MyPlace.nextLine(); +// String placeX = "", placeY = ""; +// float locationX = 0.0f, locationY = 0.0f; +// System.out.println(place); +// if (place.contains(",")) { +// String[] placeXY = place.split(","); +// placeX = placeXY[0]; +// placeY = placeXY[1]; +// +// locationX = Float.parseFloat(placeX); +// locationY = Float.parseFloat(placeY); +// } +// +// Property location = null; +// boolean isWrongData = false; +// for (Property property : Database.LoadProperties()) { +// if (property.getIndustryTitle().equals(place)) { +// location = property; +// isWrongData = true; +// } else if (String.valueOf(property.getId()).equals(place)) { +// isWrongData = true; +// location = property; +// } else if (locationX == property.getCoordinate()[0] && locationY == property.getCoordinate()[1]) { +// isWrongData = true; +// location = property; +// } +// +// } +// if (!isWrongData) { +// System.out.println("You Enter details wrongly !"); +// System.out.println("please enter again..."); +// GoTo(character); +// } +// character.gotToLocation(location); +// character.positionProcessing(); +// +// } + public void Life_Detail(Character character) { + Scanner lifeDetails = new Scanner(System.in); + System.out.println("* you can manage and check your life status : *"); + System.out.println("* food : " + character.getLife().getFood() + " *"); + System.out.println("* water : " + character.getLife().getWater() + " *"); + System.out.println("* sleep : " + character.getLife().getSleep() + " *"); + System.out.println("*************"); + System.out.println("* take a nap [1] *"); + System.out.println("* eat or drink [2] *"); + System.out.println("* back [3] *"); + System.out.println("enter your command:"); + switch (lifeDetails.next()) { + case "1" -> Sleep(character); + case "2" -> Eat(character); + case "3" -> Life(character); + } + } + + public void Sleep(Character character) { + Scanner sleep = new Scanner(System.in); + System.out.println("* we have some plan for you *"); + System.out.println("* sleep : " + character.getLife().getSleep() + " *"); + System.out.println("* +10 for 1$ [1] *"); + System.out.println("* +20 for 2$ [2] *"); + System.out.println("* +30 for 2.5$ [3] *"); + System.out.println("* cancel and back [4] *"); + System.out.println("enter your command:"); + switch (sleep.next()) { + case "1" -> sleepCharge(character, 10, 1); + case "2" -> sleepCharge(character, 20, 2); + case "3" -> sleepCharge(character, 30, 2.5f); + case "4" -> Life_Detail(character); + } + System.out.println("************"); + System.out.println("what do you want?"); + System.out.println("* charge again [1] *"); + System.out.println("* back [2] *"); + switch (sleep.next()) { + case "1" -> Sleep(character); + case "2" -> Life_Detail(character); + } + } + + private void sleepCharge(Character character, float moreSleep, float price) { + BankAccount account = character.getAccount(); + account.withdraw(character, price); + + float lastSleep = character.getLife().getSleep(); + float nowSleep = lastSleep + moreSleep; + if (nowSleep >= 100) { + nowSleep = 100.0f; + } + + Life temp = character.getLife(); + temp.setSleep(nowSleep); + + Database.updateCharacter("life", character); + + System.out.println("your new sleep status is :" + temp.getSleep()); + } + + public void Eat(Character character) { + Scanner foodScan = new Scanner(System.in); + System.out.println("you can consume product to gain water or food"); + System.out.println("* travel and shop [1] *"); + System.out.println("* cancel and back [2] *"); + + switch (foodScan.next()) { + case "1" -> GoTo(character); + case "2" -> Life_Detail(character); + } + } + + private void GoTo(Character character) { + } +} diff --git a/src/main/java/org/example/models/Employee.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Employee.java similarity index 100% rename from src/main/java/org/example/models/Employee.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Employee.java diff --git a/src/main/java/org/example/models/Food.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Food.java similarity index 100% rename from src/main/java/org/example/models/Food.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Food.java diff --git a/src/main/java/org/example/models/Industry.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Industry.java similarity index 100% rename from src/main/java/org/example/models/Industry.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Industry.java diff --git a/src/main/java/org/example/models/Job.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Job.java similarity index 100% rename from src/main/java/org/example/models/Job.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Job.java diff --git a/src/main/java/org/example/models/Liquid.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Liquid.java similarity index 100% rename from src/main/java/org/example/models/Liquid.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Liquid.java diff --git a/src/main/java/org/example/models/Manager.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Manager.java similarity index 100% rename from src/main/java/org/example/models/Manager.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Manager.java diff --git a/src/main/java/org/example/models/Property.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/Property.java similarity index 100% rename from src/main/java/org/example/models/Property.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/Property.java diff --git a/src/main/java/org/example/models/User.java b/LightCity-AmirHosseinZh/src/main/java/org/example/models/User.java similarity index 100% rename from src/main/java/org/example/models/User.java rename to LightCity-AmirHosseinZh/src/main/java/org/example/models/User.java diff --git a/LightCity-AmirHosseinZh/src/main/main.iml b/LightCity-AmirHosseinZh/src/main/main.iml new file mode 100644 index 0000000..908ad4f --- /dev/null +++ b/LightCity-AmirHosseinZh/src/main/main.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/example/AppTest.java b/LightCity-AmirHosseinZh/src/test/java/org/example/AppTest.java similarity index 100% rename from src/test/java/org/example/AppTest.java rename to LightCity-AmirHosseinZh/src/test/java/org/example/AppTest.java diff --git a/LightCity-AmirHosseinZh/src/test/test.iml b/LightCity-AmirHosseinZh/src/test/test.iml new file mode 100644 index 0000000..a0e49a3 --- /dev/null +++ b/LightCity-AmirHosseinZh/src/test/test.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/App.class b/LightCity-AmirHosseinZh/target/classes/org/example/App.class new file mode 100644 index 0000000..203b193 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/App.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/Database.class b/LightCity-AmirHosseinZh/target/classes/org/example/Database.class new file mode 100644 index 0000000..761ed12 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/Database.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/Game.class b/LightCity-AmirHosseinZh/target/classes/org/example/Game.class new file mode 100644 index 0000000..ed946e1 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/Game.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/Menu.class b/LightCity-AmirHosseinZh/target/classes/org/example/Menu.class new file mode 100644 index 0000000..3d37b48 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/Menu.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Bank.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Bank.class new file mode 100644 index 0000000..35f56d4 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Bank.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/BankTurnover.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/BankTurnover.class new file mode 100644 index 0000000..a747be9 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/BankTurnover.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/FastFoodShop.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/FastFoodShop.class new file mode 100644 index 0000000..e00a30d Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/FastFoodShop.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Life.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Life.class new file mode 100644 index 0000000..f0673a6 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Life.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Municipality.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Municipality.class new file mode 100644 index 0000000..4a4b515 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/Municipality.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/StockMarket.class b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/StockMarket.class new file mode 100644 index 0000000..a59b2de Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/defualtSystem/StockMarket.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/enumerations/Gender.class b/LightCity-AmirHosseinZh/target/classes/org/example/enumerations/Gender.class new file mode 100644 index 0000000..2c4d7de Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/enumerations/Gender.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/BankInterface.class b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/BankInterface.class new file mode 100644 index 0000000..3ef7c85 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/BankInterface.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CharacterInterface.class b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CharacterInterface.class new file mode 100644 index 0000000..dab8bee Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CharacterInterface.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CityInterface.class b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CityInterface.class new file mode 100644 index 0000000..ea47b6e Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/CityInterface.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/GameInterface.class b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/GameInterface.class new file mode 100644 index 0000000..e98919e Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/GameInterface.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/MunicipalityInterface.class b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/MunicipalityInterface.class new file mode 100644 index 0000000..8748734 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/interfaces/MunicipalityInterface.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/BankAccount.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/BankAccount.class new file mode 100644 index 0000000..b3b7de9 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/BankAccount.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Character.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Character.class new file mode 100644 index 0000000..ff19ca4 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Character.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/City.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/City.class new file mode 100644 index 0000000..764b9f9 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/City.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Employee.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Employee.class new file mode 100644 index 0000000..6d52ed1 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Employee.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Food.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Food.class new file mode 100644 index 0000000..bbbdaa9 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Food.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Industry.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Industry.class new file mode 100644 index 0000000..3e704c5 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Industry.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Job.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Job.class new file mode 100644 index 0000000..b08c49c Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Job.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Liquid.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Liquid.class new file mode 100644 index 0000000..a823d5e Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Liquid.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Manager.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Manager.class new file mode 100644 index 0000000..58cd2d3 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Manager.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/Property.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/Property.class new file mode 100644 index 0000000..568c22e Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/Property.class differ diff --git a/LightCity-AmirHosseinZh/target/classes/org/example/models/User.class b/LightCity-AmirHosseinZh/target/classes/org/example/models/User.class new file mode 100644 index 0000000..4f637d4 Binary files /dev/null and b/LightCity-AmirHosseinZh/target/classes/org/example/models/User.class differ diff --git a/LightCity-Hossein/.idea/.gitignore b/LightCity-Hossein/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/LightCity-Hossein/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/LightCity-Hossein/.idea/compiler.xml b/LightCity-Hossein/.idea/compiler.xml new file mode 100644 index 0000000..9c435a1 --- /dev/null +++ b/LightCity-Hossein/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/LightCity-Hossein/.idea/encodings.xml b/LightCity-Hossein/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/LightCity-Hossein/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/LightCity-Hossein/.idea/jarRepositories.xml b/LightCity-Hossein/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/LightCity-Hossein/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LightCity-Hossein/.idea/misc.xml b/LightCity-Hossein/.idea/misc.xml new file mode 100644 index 0000000..44185bb --- /dev/null +++ b/LightCity-Hossein/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/LightCity-Hossein/README.md b/LightCity-Hossein/README.md new file mode 100644 index 0000000..b79bccf --- /dev/null +++ b/LightCity-Hossein/README.md @@ -0,0 +1,3 @@ +Hossein GHolami: DataBase from sql +AmirHossein Ziarati: Impliment industries +Kiarash EbrahimNezhad: CLI menu(Step 2,5) diff --git a/LightCity-Hossein/pom.xml b/LightCity-Hossein/pom.xml new file mode 100644 index 0000000..ad15b26 --- /dev/null +++ b/LightCity-Hossein/pom.xml @@ -0,0 +1,39 @@ + + 4.0.0 + + org.example + GrowingInLightCity + 1.0-SNAPSHOT + jar + + GrowingInLightCity + http://maven.apache.org + + + UTF-8 + 20 + 20 + + + + + junit + junit + 3.8.1 + test + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 19 + 19 + + + + + diff --git a/LightCity-Hossein/src/main/java/org/example/App.java b/LightCity-Hossein/src/main/java/org/example/App.java new file mode 100644 index 0000000..5f21d2e --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/App.java @@ -0,0 +1,13 @@ +package org.example; + +/** + * Hello world! + * + */ +public class App +{ + public static void main( String[] args ) + { + System.out.println( "Hello World!" ); + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/Database.java b/LightCity-Hossein/src/main/java/org/example/Database.java new file mode 100644 index 0000000..ff98ec1 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/Database.java @@ -0,0 +1,142 @@ +package org.example; + +import com.sun.tools.javac.Main; +import org.example.models.Property; +import org.example.models.User; + +import javax.xml.crypto.Data; +import java.sql.*; +import java.util.ArrayList; + +public class Database { + + static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; + static final String DB_URL = "jdbc:mysql://localhost:3306/lightCity"; + + // Database credentials + static final String USER = "root"; + static final String PASS = "hossein1383"; + + + private static Connection conn; + + public Database() { + try { + Class.forName(JDBC_DRIVER); + conn = DriverManager.getConnection(DB_URL, USER, PASS); + System.out.println("Connecting to database..."); + } catch (Exception exp) { + System.out.println("Database Exception : \n" + exp.toString()); + System.exit(0); + } + } + // Tables + + /** + * Users + */ + + private void createTables() { +// query example + String query = "CREATE TABLE IF NOT EXISTS Users (username varchar(255) primary key ,password varchar(255));" + + "CREATE TABLE IF NOT EXISTS ...."; + try { + Statement stmt = conn.createStatement(); + if (stmt.execute(query)) { + + } else + System.out.println("An error accord during operation"); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + + static String userName; + static String passWord; + + public static User loginGame(User user) { + + try { + Statement stmt = conn.createStatement(); + String query = "SELECT * FROM lightCity"; + ResultSet res = stmt.executeQuery(query); + while (res.next()) { + userName = res.getString(1); + passWord = res.getString(2); + if (user.getUsername().equals(userName) && user.getPassword().equals(passWord)) { + return user; + } + } + } catch (Exception exception) { + } + return null; + } + + public static boolean notNull(User user) { + try { + Statement statement = conn.createStatement(); + ResultSet res = statement.executeQuery("SELECT * FROM users"); + if (res.next()) { + return false; + } else + return true; + } catch (Exception e) { + } + return false; + } + + public static User registerGame(User user) { + boolean isNotNull = notNull(user); + if (!isNotNull) { + try { + Statement statement = conn.createStatement(); + String query = String.format("INSERT INTO lightCity(username,password) VALUES(%s,%s)", user.getUsername(), user.getPassword()); + } catch (Exception e) { + } + } + return null; + } + + public static void saveProperties(Property property) { + String query = "INSERT INTO properties(width , height,coordinate1,coordinate2,owner) VALUES (?,?,?,?,?)"; + try { + PreparedStatement preparedStatement = conn.prepareStatement(query); + float width = property.getScales()[0]; + float height = property.getScales()[1]; + float xCoordinate = property.getCoordinate()[0]; + float yCoordinate = property.getScales()[1]; + preparedStatement.setFloat(1, width); + preparedStatement.setFloat(2, height); + preparedStatement.setFloat(3, xCoordinate); + preparedStatement.setFloat(4, yCoordinate); + if (property.getOwner() == null) { + preparedStatement.setString(5, "defaultOwner"); + } else + preparedStatement.setString(5, property.getOwner().toString()); + preparedStatement.executeUpdate(); + } catch (Exception e) { + + } + + } + + public static ArrayList getProperties() { + ArrayList getPropertiesList = new ArrayList<>(); + try { + Statement statement = conn.createStatement(); + ResultSet resultSet = statement.executeQuery("SELECT * FROM properties"); + while (resultSet.next()) { + float width = resultSet.getFloat("width"); + float height = resultSet.getFloat("height"); + float xCoordinate = resultSet.getFloat("xCoordinate"); + float yCoordinate = resultSet.getFloat("yCoordinate"); + Property property = new Property(new float[]{width, height}, new float[]{xCoordinate, yCoordinate}, null); + getPropertiesList.add(property); + } + return getPropertiesList; + } catch (Exception e) { + + } + return getPropertiesList; + } +} diff --git a/src/main/java/org/example/Game.java b/LightCity-Hossein/src/main/java/org/example/Game.java similarity index 89% rename from src/main/java/org/example/Game.java rename to LightCity-Hossein/src/main/java/org/example/Game.java index ee89f16..dc85634 100644 --- a/src/main/java/org/example/Game.java +++ b/LightCity-Hossein/src/main/java/org/example/Game.java @@ -6,6 +6,7 @@ import org.example.models.User; import java.util.ArrayList; +import java.util.Scanner; public class Game implements GameInterface { @@ -13,6 +14,10 @@ public class Game implements GameInterface { private City city; @Override public void continueGame(User user) { + if (user != null){ + + } + } /** Create new city and Generate new Character @@ -20,8 +25,11 @@ public void continueGame(User user) { * */ @Override public void startGame(User user) { + generateNewCity(); city.joinCharacter(user); + //data base;save and send data; + } /** diff --git a/LightCity-Hossein/src/main/java/org/example/Menu.java b/LightCity-Hossein/src/main/java/org/example/Menu.java new file mode 100644 index 0000000..591892d --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/Menu.java @@ -0,0 +1,197 @@ +package org.example; + +import org.example.models.User; + +import java.util.Scanner; + +public class Menu { + private static Game game = new Game(); + private static Scanner scanner = new Scanner(System.in); + + public static void showMenu() { + while (true) { + mainMenu(); + String next = scanner.next(); + if (next.equals("1")) { + game.continueGame(loginMenu()); + } else if (next.equals("2")) { + game.startGame(loginMenu()); + } else if (next.equals("3")) { + joinServer(); + } else if (next.equals("4")) + System.exit(0); + } + } + + public static void mainMenu() { +// show menu : sout () + System.out.println("****************************"); + System.out.println("*** 1-Continue ***"); + System.out.println("*** 2-Start New Game ***"); + System.out.println("*** 3-Join Server ***"); + System.out.println("*** 4-Exit ***"); + System.out.println("****************************"); + + } + + public static void userMenu()//print option for user + { + System.out.println("****************************"); + System.out.println("*** 1-Go to ***"); + System.out.println("*** 2-Process Location ***"); + System.out.println("*** 3-Dashboard ***"); + System.out.println("*** 4-Life ***"); + System.out.println("*** 5-Exit ***"); + System.out.println("****************************"); + } + + public static void showUserMenu(User user)// + { + userMenu(); + String next = scanner.next(); + switch (next) { + case "1": { + System.out.println("** Enter location (1 or 2) **"); + System.out.println("** a. Location ID **"); + System.out.println("** b. Industry Title **"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.out.print("Enter Your Location ID : "); + String LocationId = scanner.next(); + //complete this part + } else if (nextGoTo.equals("b")) { + System.out.print("Enter Your Industry Title : "); + String IndustryTitle = scanner.next(); + //complete this part + } + } + case "2": { + System.out.println("** Show Detail (1 or 2) **"); + System.out.println("** a. Show where is character : Property detail {position , title,…} **"); + System.out.println("** b. Show options according to Industry and Property ownership **"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + //kia(level of user) + //complete this part + } else if (nextGoTo.equals("b")) { + //option of user industry + //complete this part + } + } + case "3": { + System.out.println("a. My Job"); + System.out.println("b. Properties"); + System.out.println("c. Economy"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.out.println("i. Find Job"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //find job + } + } else if (nextGoTo.equals("b")) { + System.out.println("i. Show Properties"); + System.out.println("ii. Sell"); + System.out.println("iii. Management"); + System.out.println("iv. Found Industry"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //show prprty + } else if (nextGoToOptions.equals("ii")) { + //sell + } else if (nextGoToOptions.equals("iii")) { + //management + } else if (nextGoToOptions.equals("iv")) { + //found indstry + } + } else if (nextGoTo.equals("c")) { + System.out.println("i. Show Incomes"); + System.out.println("ii. Show Job Detail"); + System.out.println("iii. How Can Grow Up"); + String nextGoToOptions = scanner.next(); + if (nextGoToOptions.equals("i")) { + //show incomes + } else if (nextGoToOptions.equals("ii")) { + //show job detail + } else if (nextGoToOptions.equals("iii")) { + //H C Grow Up + } + } + } + case ("4"): { + System.out.println("a. Life Detail"); + System.out.println("b. Sleep Function"); + System.out.println("c. Eat Function"); + System.out.println("d. Show (Food , Water , Sleep) Percent"); + } + case ("5"): { + System.out.println("a. Are You Sure?"); + String nextGoTo = scanner.next(); + if (nextGoTo.equals("a")) { + System.exit(0); + } + } + } + } + + public static User loginMenu() { + boolean b = true; + while (b) { + Scanner input = new Scanner(System.in); + System.out.print("** Enter your username : "); + String username = input.nextLine(); + System.out.print("** Enter your password: "); + String password = input.nextLine(); + User user = new User(username, password); + if (Database.loginGame(user) != null) { + return user; + } else { + System.out.println("1. logIn"); + System.out.println("2. signUp"); + String temp = input.nextLine(); + switch (temp) { + case "1" -> loginMenu(); + case "2" -> registerMenu(); + case "3" -> b = false; + } + } + } + return null; + } + + private static void joinServer() { + System.out.print("Enter Server Ip Address :"); + String ip = scanner.next(); + System.out.print("Enter Server Port :"); + int port = scanner.nextInt(); + game.joinServer(ip, port); + } + + public static User registerMenu() { + boolean b = true; + while (b){ + Scanner input = new Scanner(System.in); + System.out.print("** Enter your username : "); + String username = input.nextLine(); + System.out.print("** Enter your password: "); + String password = input.nextLine(); + User user = new User(username, password); + if (Database.loginGame(user) != null) { + return user; + } else { + System.out.println("1. logIn"); + System.out.println("2. back"); + } + String next = input.nextLine(); + switch (next) { + case "1" -> loginMenu(); + case "2" -> b = false; + } + } + return null; + } + + public static void main(String[] args) { + showMenu(); + } +} diff --git a/src/main/java/org/example/defualtSystem/Bank.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/Bank.java similarity index 100% rename from src/main/java/org/example/defualtSystem/Bank.java rename to LightCity-Hossein/src/main/java/org/example/defualtSystem/Bank.java diff --git a/LightCity-Hossein/src/main/java/org/example/defualtSystem/BankTurnover.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/BankTurnover.java new file mode 100644 index 0000000..6695351 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/defualtSystem/BankTurnover.java @@ -0,0 +1,20 @@ +package org.example.defualtSystem; + +public class BankTurnover { + private double withdraw = 0; + private double deposit = 0; + + /** + * @param amount : Money amount + * @param type : -1 for withdraw , +1 for deposit + * */ + public void transfer(float amount,int type){ + if(type == 1) + deposit=amount; + else if (type==-1) + withdraw+=amount; + } + public double calcTurnover(){ + return deposit-withdraw; + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/defualtSystem/FastFoodShop.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/FastFoodShop.java new file mode 100644 index 0000000..2c178cf --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/defualtSystem/FastFoodShop.java @@ -0,0 +1,17 @@ +package org.example.defualtSystem; + +import org.example.models.Character; +import org.example.models.Industry; +import org.example.models.Property; + +public class FastFoodShop extends Industry { + + /** + * Industry type example (Business) + * */ + private static final float INCOME = 0.3f; + private static final float EMPLOYEE_INCOME = 0.02f; + public FastFoodShop(String title, Property property, Character character) { + super(title, property, character,EMPLOYEE_INCOME); + } +} diff --git a/src/main/java/org/example/defualtSystem/Life.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/Life.java similarity index 100% rename from src/main/java/org/example/defualtSystem/Life.java rename to LightCity-Hossein/src/main/java/org/example/defualtSystem/Life.java diff --git a/LightCity-Hossein/src/main/java/org/example/defualtSystem/Municipality.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/Municipality.java new file mode 100644 index 0000000..92781bf --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/defualtSystem/Municipality.java @@ -0,0 +1,33 @@ +package org.example.defualtSystem; + +import org.example.interfaces.MunicipalityInterface; +import org.example.models.Property; + +import java.util.ArrayList; + +public class Municipality implements MunicipalityInterface { + private ArrayList properties; + + public Municipality(){ + generateProperties(); + } + + private void generateProperties() { +// Create an algorithm for generating properties for city + } + + @Override + public Property buyProperty() { + return null; + } + + @Override + public void sellProperty(Property property) { + + } + + @Override + public void showProperties() { + + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/defualtSystem/StockMarket.java b/LightCity-Hossein/src/main/java/org/example/defualtSystem/StockMarket.java new file mode 100644 index 0000000..5f06660 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/defualtSystem/StockMarket.java @@ -0,0 +1,63 @@ +package org.example.defualtSystem; + +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +public class StockMarket{ + private Map users; + + public StockMarket() { + users = new HashMap<>(); + } + + public synchronized void depositCapital(String userName, double amount) { + if (users.containsKey(userName)) { + double currentCapital = users.get(userName); + users.put(userName, currentCapital + amount); + } else { + users.put(userName, amount); + } + } + + public synchronized double getDetail(String userName) { + if (users.containsKey(userName)) { + return users.get(userName); + } else { + return 0.0; + } + } + + public synchronized double withdrawCapital(String userName) { + if (users.containsKey(userName)) { + double amount = users.get(userName); + users.put(userName, 0.0); + return amount; + } else { + return 0.0; + } + } + + public void startMarketSimulation() { + Thread marketThread = new Thread(() -> { + Random random = new Random(); + while (true) { + double change = random.nextDouble() * 0.06 - 0.03; + for (String userName : users.keySet()) { + double capital = users.get(userName); + double newCapital = capital + capital * change; + if (newCapital < 0) { + newCapital = 0; + } + users.put(userName, newCapital); + } + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + marketThread.start(); + } +} \ No newline at end of file diff --git a/LightCity-Hossein/src/main/java/org/example/enumerations/Gender.java b/LightCity-Hossein/src/main/java/org/example/enumerations/Gender.java new file mode 100644 index 0000000..dc64618 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/enumerations/Gender.java @@ -0,0 +1,5 @@ +package org.example.enumerations; + +public enum Gender { + Male,Female +} diff --git a/LightCity-Hossein/src/main/java/org/example/interfaces/BankInterface.java b/LightCity-Hossein/src/main/java/org/example/interfaces/BankInterface.java new file mode 100644 index 0000000..f8bb551 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/interfaces/BankInterface.java @@ -0,0 +1,4 @@ +package org.example.interfaces; + +public interface BankInterface { +} diff --git a/LightCity-Hossein/src/main/java/org/example/interfaces/CharacterInterface.java b/LightCity-Hossein/src/main/java/org/example/interfaces/CharacterInterface.java new file mode 100644 index 0000000..7e3529f --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/interfaces/CharacterInterface.java @@ -0,0 +1,6 @@ +package org.example.interfaces; + +public interface CharacterInterface { + void positionProcessing(); + +} diff --git a/LightCity-Hossein/src/main/java/org/example/interfaces/CityInterface.java b/LightCity-Hossein/src/main/java/org/example/interfaces/CityInterface.java new file mode 100644 index 0000000..42be3a9 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/interfaces/CityInterface.java @@ -0,0 +1,9 @@ +package org.example.interfaces; + +import org.example.models.Character; +import org.example.models.User; + +public interface CityInterface { + void joinCharacter(User character); + void getCityDetail(); +} diff --git a/LightCity-Hossein/src/main/java/org/example/interfaces/GameInterface.java b/LightCity-Hossein/src/main/java/org/example/interfaces/GameInterface.java new file mode 100644 index 0000000..4e2d808 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/interfaces/GameInterface.java @@ -0,0 +1,15 @@ +package org.example.interfaces; + +import org.example.models.Character; +import org.example.models.User; + +public interface GameInterface { + void continueGame(User user); + void startGame(User user); + + void joinServer(String ip ,int port); + + void generateNewCity(); + + +} diff --git a/LightCity-Hossein/src/main/java/org/example/interfaces/MunicipalityInterface.java b/LightCity-Hossein/src/main/java/org/example/interfaces/MunicipalityInterface.java new file mode 100644 index 0000000..f2f0ea2 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/interfaces/MunicipalityInterface.java @@ -0,0 +1,11 @@ +package org.example.interfaces; + +import org.example.models.Property; + +public interface MunicipalityInterface { + +// Buy and sell property + Property buyProperty(); + void sellProperty(Property property); + void showProperties(); +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/BankAccount.java b/LightCity-Hossein/src/main/java/org/example/models/BankAccount.java new file mode 100644 index 0000000..8c5e27d --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/BankAccount.java @@ -0,0 +1,72 @@ +package org.example.models; + +import org.example.defualtSystem.Bank; + +import java.util.Date; + +public class BankAccount { + private String owner; + private String password; + private float money; + private Date lastChange; + + private String logs = ""; + + public BankAccount(String owner, String password, float money, Date lastChange) { + this.owner = owner; + this.password = password; + this.money = money; + this.lastChange = lastChange; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public float getMoney() { + return money; + } + + + public Date getLastChange() { + return lastChange; + } + + public void setLastChange(Date lastChange) { + this.lastChange = lastChange; + } + + public boolean withdraw(Character character,float amount){ + if(character.getUserInfo().getUsername().equals(owner)){ + if(amount <= money){ + Bank.turnover.transfer(amount,-1); + money-= amount; + return true; + }else + return false; + } + return false; + } + public boolean deposit(Character character,float amount){ + if(amount >0){ + String log = String.format("User : %s deposit %f \n",character.getUserInfo().getUsername(),amount); + logs+=log; + Bank.turnover.transfer(amount,1); + money += amount; + return true; + } + return false; + } +} diff --git a/src/main/java/org/example/models/Character.java b/LightCity-Hossein/src/main/java/org/example/models/Character.java similarity index 100% rename from src/main/java/org/example/models/Character.java rename to LightCity-Hossein/src/main/java/org/example/models/Character.java diff --git a/src/main/java/org/example/models/City.java b/LightCity-Hossein/src/main/java/org/example/models/City.java similarity index 100% rename from src/main/java/org/example/models/City.java rename to LightCity-Hossein/src/main/java/org/example/models/City.java diff --git a/LightCity-Hossein/src/main/java/org/example/models/Employee.java b/LightCity-Hossein/src/main/java/org/example/models/Employee.java new file mode 100644 index 0000000..81e8fbc --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Employee.java @@ -0,0 +1,47 @@ +package org.example.models; + +public class Employee { + private String username; + private float baseSalary ; + private int level; + + private BankAccount bankAccount; + + private Industry industry; + + public Employee(String username,Industry industry, float baseSalary,BankAccount bankAccount) { + this.username = username; + this.baseSalary = baseSalary; + this.industry = industry; + this.level = 1; + this.bankAccount = bankAccount; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public float getBaseSalary() { + return baseSalary; + } + + public void setBaseSalary(float baseSalary) { + this.baseSalary = baseSalary; + } + + public int getLevel() { + return level; + } + + public void setLevel(int level) { + this.level = level; + } + + public void paySalary(){ + bankAccount.deposit(industry.getOwner(),level*baseSalary); + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Food.java b/LightCity-Hossein/src/main/java/org/example/models/Food.java new file mode 100644 index 0000000..b94d900 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Food.java @@ -0,0 +1,32 @@ +package org.example.models; + +public class Food { + + private String title; + private final float water; + private final float food; + + public boolean available = true; + + public Food(String title,float food,float water) { + this.food = food; + this.water = water; + this.title = title; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getWater() { + return water; + } + + public float getFood() { + return food; + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Industry.java b/LightCity-Hossein/src/main/java/org/example/models/Industry.java new file mode 100644 index 0000000..b3bf20b --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Industry.java @@ -0,0 +1,65 @@ +package org.example.models; + +import java.util.ArrayList; +import java.util.List; + +public class Industry extends Property{ + private String title; + private float income; + + protected ArrayList employees = new ArrayList<>(); + + /** + * @param title : A Title for generate Industry @example : Bank extends Industry then title = "Bank" + * @param property : Industry owner should have a Property to create this industry on it + * @param character : Industry owner + * @param income : Each Business has a class like Bank and extends Industry , in super method Enter the desired monthly income amount + * */ + public Industry(String title,Property property,Character character,float income) { + super(property.getScales(),property.getCoordinate(),character); + this.title = title; + this.income = income; + startPaySalary(); + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getIncome() { + return income; + } + + public void setIncome(float income) { + this.income = income; + } + + + public ArrayList getEmployee() { + return employees; + } + + public void setEmployee(ArrayList employee) { + this.employees = employee; + } + + public void startPaySalary(){ + Thread thread = new Thread(()->{ + while (true){ + employees.stream().forEach((employee)->{ + employee.paySalary(); + }); + try { + Thread.sleep(10800000); // wait for 1 minute + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + }); + thread.start(); + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Job.java b/LightCity-Hossein/src/main/java/org/example/models/Job.java new file mode 100644 index 0000000..ac8c655 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Job.java @@ -0,0 +1,42 @@ +package org.example.models; + +public class Job { + private String title; + private float income; + private String industryId; + + /** + * @param title : Industry title + * @param income : industry The monthly income of its employees + * @param industryId : industry id + * */ + public Job(String title, float income, String industryId) { + this.title = title; + this.income = income; + this.industryId = industryId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public float getIncome() { + return income; + } + + public void setIncome(float income) { + this.income = income; + } + + public String getIndustryId() { + return industryId; + } + + public void setIndustryId(String industryId) { + this.industryId = industryId; + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Liquid.java b/LightCity-Hossein/src/main/java/org/example/models/Liquid.java new file mode 100644 index 0000000..3b8cb59 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Liquid.java @@ -0,0 +1,16 @@ +package org.example.models; + +public class Liquid { + private final float liquid; + + public boolean available =true; + + public Liquid(float liquid) { + this.liquid = liquid; + } + + public float getLiquid() { + return liquid; + } + +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Manager.java b/LightCity-Hossein/src/main/java/org/example/models/Manager.java new file mode 100644 index 0000000..4d7464d --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Manager.java @@ -0,0 +1,8 @@ +package org.example.models; + +public class Manager extends Employee{ + + public Manager(String username, Industry industry, float baseSalary, BankAccount bankAccount) { + super(username, industry, baseSalary, bankAccount); + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/Property.java b/LightCity-Hossein/src/main/java/org/example/models/Property.java new file mode 100644 index 0000000..94c8029 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/Property.java @@ -0,0 +1,37 @@ +package org.example.models; + +public class Property { + private float[] scales; + private float[] coordinate; + private Character owner ; + + public Property(float[] scales, float[] coordinate, Character owner) { + this.scales = scales; + this.coordinate = coordinate; + this.owner = owner; + } + + public float[] getScales() { + return scales; + } + + public void setScales(float[] scales) { + this.scales = scales; + } + + public Character getOwner() { + return owner; + } + + public void setOwner(Character owner) { + this.owner = owner; + } + + public float[] getCoordinate() { + return coordinate; + } + + public void setCoordinate(float[] coordinate) { + this.coordinate = coordinate; + } +} diff --git a/LightCity-Hossein/src/main/java/org/example/models/User.java b/LightCity-Hossein/src/main/java/org/example/models/User.java new file mode 100644 index 0000000..c834866 --- /dev/null +++ b/LightCity-Hossein/src/main/java/org/example/models/User.java @@ -0,0 +1,37 @@ +package org.example.models; + +public class User { + private String username; + private String password; + + public User() + { + + } + public User(String username, String password) { + this.username = username; + this.password = password; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void sign(String username,String password) + { + setPassword(password); + setUsername(username); + } +} diff --git a/LightCity-Hossein/src/test/java/org/example/AppTest.java b/LightCity-Hossein/src/test/java/org/example/AppTest.java new file mode 100644 index 0000000..d5f435d --- /dev/null +++ b/LightCity-Hossein/src/test/java/org/example/AppTest.java @@ -0,0 +1,38 @@ +package org.example; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +} diff --git a/README.md b/README.md index d05545f..b79bccf 100644 --- a/README.md +++ b/README.md @@ -1,52 +1,3 @@ -# Growing In Lightcity Project - -This project is a city-building game that includes various features and systems. The objective is to understand the game logic and design it accordingly. - -## Getting Started - -To get started with the project, you need to fork it - -### Prerequisites - -The project contains an initial structure and some implemented systems. Each team member is responsible for implementing a specific system. - -## User Interface - -The user interface section includes tasks such as user registration, login, and character creation. You should also examine the game loop and implement each system and feature as you encounter them. - -The project structure is highly flexible, allowing for modifications and additions in any direction desired. The game logic remains constant, but you can add or direct branches as needed. - -## City Structure - -The city structure is partially implemented, and certain algorithms, such as property creation upon the municipality's creation, are missing. You should implement these algorithms based on the desired city structure. For example, you can create 20 lands with dimensions of 40x80 using a simple loop to generate the properties. - -Pay attention to the existing algorithms, such as the stock market's capital increase and decrease. Think about how you can create a menu for interacting with this section or how you can display charts and detailed information about investments. Feel free to be creative and make any necessary changes, even to the initial structure, by informing the exercise solver. - -No system is devoid of flexibility. Embrace creativity and progress each topic one by one. - -## Structure Overview - -The following is an overview of the initial structure and implemented classes: - -1. **Game**: The Game class contains information about cities and the overall game structure. -2. **City**: The City class contains a list of characters, a bank system, a municipality, and the root character. -3. **Municipality**: The Municipality class generates properties based on a specific algorithm (you need to devise this algorithm). It also contains a list of properties and property operations such as buying and selling. -4. **Character**: The Character class includes user information, a bank account, a life system, a job (can be null), a list of owned properties, and the character's current position property. -5. **User**: The User class includes the username and password. -6. **Job**: The Job class includes the job title, income, and industry ID. -7. **Employee**: The Employee class is generated when a character joins an industry. It includes the username, base salary, level, bank account, and industry. -8. **Manager**: [No further information provided] -9. **Bank**: The Bank class includes a list of accounts, a manager (root), and the bank's turnover. -10. **BankTurnOver**: The BankTurnOver class includes income and outcome. -11. **BankAccount**: The BankAccount class represents the owner (a character), password, money, and the last change date. -12. **Property**: The Property class includes an array of scales, an array of coordinates, and the owner. -13. **StockMarket**: The StockMarket system works with the character's money and generates a profit or loss per second within the range of -0.03 to +0.03. -14. **Food & Liquid**: Includes water and food options. -15. **Industry**: The Industry class includes the title, income, and a list of employees. - -And other interfaces... - -## Contributing - -Feel free to contribute to the project by suggesting improvements or implementing new features. -`` +Hossein GHolami: DataBase from sql +AmirHossein Ziarati: Impliment industries +Kiarash EbrahimNezhad: CLI menu(Step 2,5) diff --git a/src/main/java/org/example/Database.java b/src/main/java/org/example/Database.java deleted file mode 100644 index 7051ba7..0000000 --- a/src/main/java/org/example/Database.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.example; - -import org.example.models.User; - -import javax.xml.crypto.Data; -import java.sql.*; - -public class Database { - - static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; - static final String DB_URL = "jdbc:mysql://localhost/lightcity"; - - // Database credentials - static final String USER = "your_username"; - static final String PASS = "your_password"; - - - private Connection conn; - - public Database() { - try { - Class.forName(JDBC_DRIVER); - conn = DriverManager.getConnection(DB_URL, USER, PASS); - System.out.println("Connecting to database..."); - } catch (Exception exp) { - System.out.println("Database Exception : \n" + exp.toString()); - System.exit(0); - } - } - // Tables - - /** - * Users - */ - - private void createTables() { -// query example - String query = "CREATE TABLE IF NOT EXISTS Users (username varchar(255) primary key ,password varchar(255));" + - "CREATE TABLE IF NOT EXISTS ...."; - try { - Statement stmt = conn.createStatement(); - if(stmt.execute(query)){ - - }else - System.out.println("An error accord during operation"); - } catch (SQLException e) { - throw new RuntimeException(e); - } - - - } - - public void loginGame(User user) { - try { - Statement stmt = conn.createStatement(); - String query = ""; - ResultSet res = stmt.executeQuery(query); - while (res.next()) { -// Check - } - } catch (Exception exception) { - } - - } - - public void registerGame(User user) { - } - -} diff --git a/src/main/java/org/example/Menu.java b/src/main/java/org/example/Menu.java deleted file mode 100644 index b5086e6..0000000 --- a/src/main/java/org/example/Menu.java +++ /dev/null @@ -1,41 +0,0 @@ -package org.example; - -import org.example.models.User; - -import java.util.Scanner; - -public class Menu { - private static Game game = new Game(); - private static Scanner scanner = new Scanner(System.in); - public static void showMenu(){ - mainMenu(); - String next = scanner.next(); - if (next.equals("1")) { - game.continueGame(loginMenu()); - }else if(next.equals("2")){ - game.startGame(loginMenu()); - }else if (next.equals("3")){ - joinServer(); - }else if (next.equals("4")) - System.exit(0); - } - public static void mainMenu(){ -// show menu : sout () - } - - public static User loginMenu(){ -// get user info : username, password - return null; - } - - private static void joinServer(){ - System.out.print("Enter Server Ip Address :"); - String ip = scanner.next(); - System.out.print("Enter Server Port :"); - int port = scanner.nextInt(); - game.joinServer(ip,port); - } - public static void main(String[] args) { - showMenu(); - } -}