diff --git a/TaipanClone.iml b/TaipanClone.iml index a860761..c90834f 100644 --- a/TaipanClone.iml +++ b/TaipanClone.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class deleted file mode 100644 index d6a3b07..0000000 Binary files a/out/production/TaipanClone/ShipWarfare.class and /dev/null differ diff --git a/src/Bank.java b/src/Bank.java deleted file mode 100644 index e8206eb..0000000 --- a/src/Bank.java +++ /dev/null @@ -1,102 +0,0 @@ -import java.util.Scanner; - -public class Bank{ - private Player player; - - /** - * setter method that takes in a Player object as an argument. - * - * @param player object of the class Player - */ - - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * getter method for obtaining a player object. - * - * @return returns player object - */ - - public Player getPlayer(){ - Player playerDummy = new Player(player); - return playerDummy; - } - /** - * Class Constructor that takes in a type player as a parameter - * - * @param player object of the class Player - */ - - public Bank(Player player){ - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * This method is used to withdraw or deposit money into the bank account - * by prompting the user if they would like to withdraw or deposit. Followed - * by prompting them to enter an amount to transfer. This method also uses the - * player class to see if the transfer can be made,and if it can it changes the - * values accordingly - */ - public void bank(){ - Scanner input = new Scanner(System.in); - boolean notDone = true; - int check = 0; - while(notDone){ - //Prompt the user if they want to withdraw or deposit - System.out.println("Would you like to Withdraw or Deposit?"); - String response = input.nextLine(); - //If user chose withdraw then subtract the amount from bank account and add it to cash - if(response.equalsIgnoreCase("W")){ - boolean notDone2 = true; - while(notDone2){ - System.out.println("How much do you wish to Withdraw?"); - int withdraw = input.nextInt(); - //Prompt the user for the amount and check if the bank has sufficient funds - if(withdraw <= player.getBank()){ - player.setMoney(withdraw + player.getMoney()); - player.setBank(player.getBank()-withdraw); - notDone2 = false; - check = 1; - } - } - - } - //If the user chooses to deposit the continue to this code - else if(response.equalsIgnoreCase("D")){ - boolean notDone2 = true; - while(notDone2){ - //Prompt the user for the amount they would like to deposit and ensure suffiecent funds - System.out.println("How much do you wish to Deposit?"); - int deposit = input.nextInt(); - if(deposit <= player.getMoney()){ - player.setBank(deposit + player.getBank()); - player.setMoney(player.getMoney()-deposit); - notDone2 = false; - check = 1; - } - } - } - if(check == 1){ - boolean notDone3 = true; - // Asks user if they would like to continue in bank or not - while(notDone3){ - System.out.println("Would you like to continue? Y/N"); - response = input.nextLine(); - response = input.nextLine(); - if(response.equalsIgnoreCase("Y")){ - notDone3 = false; - }else if(response.equalsIgnoreCase("N")){ - notDone = false; - notDone3 = false; - } - } - } - } - - } -} diff --git a/src/MainGUI.java b/src/MainGUI.java index f5ab1df..ea527e3 100644 --- a/src/MainGUI.java +++ b/src/MainGUI.java @@ -28,19 +28,6 @@ public class MainGUI extends Application { player = shop.getPlayer(); } - /** - * Initializes the player object with 5 guns or $400 and $5000 debt. - * - * @param start player object from the main class used to update the start class - */ - - public void start(Start start){ - start.setPlayer(player); - start.initialize(); - player = start.getPlayer(); - } - - /** * Updates main class with player data and starts the game. * The game will only run as long as the player has not retired or has been destroyed. diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java deleted file mode 100644 index 99d2071..0000000 --- a/src/ShipWarfare.java +++ /dev/null @@ -1,465 +0,0 @@ -import java.util.Scanner; -import java.util.Random; -import java.util.concurrent.TimeUnit; - - -public class ShipWarfare { - - private int numOfPeasantShips = 0; - private int numOfLittyShips = 0; - private boolean userAttacks = true; - private int startingPeasantShips = 0; - private int startingLittyShips = 0; - private int howMuchRun = 0; - private String pirateName = "Liu Yen"; - private Player player; - - /** - * Class Constructor that takes in a type player as a parameter - * @param player object of the class Player - */ - public ShipWarfare(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * setter method for player - * @param player object of the class Player - */ - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * getter method for obtaining a player object. - * @return returns player object - */ - public Player getPlayer() { - Player playerDummy = new Player(player); - return playerDummy; - } - - /** - * This fleet is easy to defeat as a maximum of 15 ships can run away each volley, they can not tank hits - * @throws Exception in case of errors due to the delay - */ - public void peasantFleetAttack() throws Exception { - Scanner userResponse = new Scanner(System.in); - setNumOfPeasantShips(numOfShips()); - - System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP()); - - fightOrRunMessage(); - while (true) { - String response = userResponse.nextLine(); - if (response.equalsIgnoreCase("f")) { - userAttacks = true; - System.out.println("Ohh, fight ehh?"); - delayForSeconds(1); - boolean winOrLose = destroyPeasantShipsOrEscape(); - if (winOrLose == true) { - break; - } - - - } else if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away!"); - if (destroyPeasantShipsOrEscape()) - break; - } else { - System.out.println("Phew! Got away safely"); - delayForSeconds(2); - break; - } - - } - - } - - - } - - /** - * This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits - * @throws Exception in case of errors due to the delay - */ - public void littyFleetAttack() throws Exception { - Scanner userResponse = new Scanner(System.in); - setNumOfLittyShips(numOfShips()); - System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfLittyShips, pirateName, player.getHP()); - fightOrRunMessage(); - while (true) { - String response = userResponse.nextLine(); - if (response.equalsIgnoreCase("f")) { - userAttacks = true; - System.out.println("Ohh, fight ehh?"); - boolean winOrLose = destroyLittyShipsOrEscape(); - if (winOrLose == true) { - break; - } - - - } else if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away!"); - delayForSeconds(1); - if (destroyLittyShipsOrEscape()) - break; - } else { - System.out.println("Phew! Got away safely"); - delayForSeconds(2); - break; - } - - } - - } - - - } - - /** - * Asks user if they would like to fight or run against ships - */ - - public void fightOrRunMessage() { - System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)\n", player.getGuns()); - - } - - /** - * setter method that takes in an integer as an argument - * @param numOfLittyShips the number of ships to be used in the litty fleet attack - */ - public void setNumOfLittyShips(int numOfLittyShips) { - this.numOfLittyShips = numOfLittyShips; - startingLittyShips = numOfLittyShips; - - } - - /** - * setter method that takes in an integer as an argument - * @param numOfPeasantShips the number of ships to be used in the peasant fleet attack - */ - - public void setNumOfPeasantShips(int numOfPeasantShips) { - this.numOfPeasantShips = numOfPeasantShips; - startingPeasantShips = numOfPeasantShips; - - } - - /** - * delays for a specific amount of seconds, takes an integer as an argument - * @param num the seconds to delay - * @throws Exception in case of errors due to the delay - */ - public void delayForSeconds(int num) throws Exception { - TimeUnit.SECONDS.sleep(num); - } - - /** - * The number of ships that attack is based on the amount of money one has on hand - * @return the number of ships which will attack - */ - public int numOfShips() { - - int numOfShipsAttacking = 0; - Random randomValue = new Random(); - - if (player.getMoney() <= 100000) { - //Minimum one ship will attack, maximum 20 - numOfShipsAttacking = randomValue.nextInt(20) + 1; - } else if (player.getMoney() <= 200000) { - //Minimum 30 Ships will attack, maximum 70 - numOfShipsAttacking = randomValue.nextInt(40) + 30; - } else if (player.getMoney() <= 500000) { - //Minimum 50 ships will attack, maximum 140 - numOfShipsAttacking = randomValue.nextInt(90) + 50; - } else if (player.getMoney() > 1000000) { - //Minimum 100 ships will attack, maximum 300 ships - numOfShipsAttacking = randomValue.nextInt(3) + 100; - } - - return numOfShipsAttacking; - - } - - /** - * One in two chance of running away - * @return true if the user is allowed to run, false if not, the "default" is false - */ - - public boolean runFromShips() { - userAttacks = false; - Random randomValue = new Random(); - int runSuccessChance = randomValue.nextInt(2) + 1; - if (runSuccessChance == 2) { - return true; - } else if (runSuccessChance == 1) { - return false; - } - return false; - } - - /** - * The user faces off against the litty ships and either prevails, dies, or runs away - * The loot for defeating a litty fleet is much higher than that of a peasant one - * @return true if the user wins, loses, or flees, it returns false otherwise - * @throws Exception in case of errors due to the delay - */ - public boolean destroyLittyShipsOrEscape() throws Exception { - int calculateLoot = 0; - int chanceOfEnemyRun = 0; - - - Scanner userInput = new Scanner(System.in); - Random randomValue = new Random(); - int exitValue = 0; - - //Player volley - while (exitValue == 0) { - if (player.getGuns() > 0) { - for (int j = 0; j < player.getGuns(); j++) { - if (userAttacks == true) { - int hitOrMiss = randomValue.nextInt(3) + 1; - if (hitOrMiss == 1) { - numOfLittyShips--; - if (numOfLittyShips <= 0) { - exitValue = 1; - break; - } - System.out.println("Got eem"); - delayForSeconds(1); - } else if (hitOrMiss == 2) { - System.out.printf("ARRG! We missed %s\n", player.getName()); - delayForSeconds(1); - } else { - System.out.println("Darn! Their fleet tanked our attack"); - delayForSeconds(1); - } - - - } else { - continue; - } - } - } else { - System.out.printf("%s! We don't have any GUNS!!!!\n",player.getName()); - delayForSeconds(1); - } - - - if (numOfLittyShips <= 0) { - exitValue = 1; - break; - } - if (player.getGuns() > 0) { - if (chanceOfEnemyRun == 2) { - chanceOfEnemyRun = randomValue.nextInt(2) + 1; - howMuchRun = randomValue.nextInt(10) + 1; - if (howMuchRun != 0 && howMuchRun < numOfLittyShips) { - - - setNumOfLittyShips(numOfLittyShips - howMuchRun); - if (userAttacks == true) { - System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, player.getName()); - } else { - System.out.printf("Escaped %d of them!\n", howMuchRun); - } - } - } - } - - System.out.printf("%d ships remaining\n", numOfLittyShips); - System.out.println("Oh no, they are taking the offensive!"); - delayForSeconds(1); - //Computer volley - int takeGunChance = randomValue.nextInt(4) + 1; - if (takeGunChance == 1 && player.getGuns() > 0) { - player.setGuns(player.getGuns() - 1); - System.out.println("Dang it! They destroyed one of our guns"); - } else { - player.setHP(player.getHP() - (1 + randomValue.nextInt(15))); - } - if (player.getHP() <= 0) { - exitValue = 2; - break; - } - System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); - delayForSeconds(1); - if (userAttacks == false) { - userAttacks = true; - } - - System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); - - String response = userInput.nextLine(); - if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away"); - delayForSeconds(1); - } else { - System.out.println("Phew! Got away safely"); - delayForSeconds(2); - break; - } - } - - - } - - - if (exitValue == 1) { - System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); - delayForSeconds(1); - calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; - player.setMoney(player.getMoney() + calculateLoot); - System.out.printf("We got $%,d!\n", calculateLoot); - delayForSeconds(2); - return true; - } else if (exitValue == 2) { - player.gameOver(); - - return true; - } else if (exitValue == 3) { - System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); - delayForSeconds(2); - return true; - } - return false; - - - } - - /** - * The user faces off against the peasant ships and either prevails, dies, or runs away - * @return true if the user wins, loses, or flees, it returns false otherwise - * @throws Exception in case of errors due to the delay - */ - - public boolean destroyPeasantShipsOrEscape() throws Exception { - int calculateLoot = 0; - int chanceOfEnemyRun = 0; - - - Scanner userInput = new Scanner(System.in); - Random randomValue = new Random(); - int exitValue = 0; - - //Player volley - while (exitValue == 0) { - if (player.getGuns() > 0) { - - for (int j = 0; j < player.getGuns(); j++) { - if (userAttacks == true) { - int hitOrMiss = randomValue.nextInt(2) + 1; - if (hitOrMiss == 2) { - numOfPeasantShips--; - if (numOfPeasantShips <= 0) { - exitValue = 1; - break; - } - System.out.println("Got eem"); - delayForSeconds(1); - } else { - System.out.printf("ARRG! We missed %s\n", player.getName()); - delayForSeconds(1); - } - - - } else { - continue; - } - } - } - else{ - System.out.printf("%s! We don't have any GUNS!!!!\n", player.getName()); - delayForSeconds(1); - - } - - - if (numOfPeasantShips <= 0) { - exitValue = 1; - break; - } - if (player.getGuns() > 0) { - chanceOfEnemyRun = randomValue.nextInt(2) + 1; - if (chanceOfEnemyRun == 2) { - howMuchRun = randomValue.nextInt(15) + 1; - if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) { - - - setNumOfPeasantShips(numOfPeasantShips - howMuchRun); - if (userAttacks == true) { - System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName()); - } else { - System.out.printf("Escaped %d of them!\n", howMuchRun); - } - } - } - } - - System.out.printf("%d ships remaining\n", numOfPeasantShips); - delayForSeconds(1); - System.out.println("Oh no, they are taking the offensive!"); - delayForSeconds(1); - //Computer volley - int takeGunChance = randomValue.nextInt(4) + 1; - if (takeGunChance == 1 && player.getGuns() > 0) { - player.setGuns(player.getGuns() - 1); - System.out.println("Dang it! They destroyed one of our guns"); - } else { - player.setHP(player.getHP() - (1 + randomValue.nextInt(10))); - } - if (player.getHP() <= 0) { - exitValue = 2; - break; - } - System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); - delayForSeconds(1); - if (userAttacks == false) { - userAttacks = true; - } - - System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); - - String response = userInput.nextLine(); - if (response.equalsIgnoreCase("r")) { - if (runFromShips() == false) { - System.out.println("Couldn't run away"); - } else { - exitValue = 3; - break; - } - } - - - } - - - if (exitValue == 1) { - System.out.printf("\nGot eem\nVictory!\nIt appears we have defeated the enemy fleet and made it out at %d%% ship status\n", player.getHP()); - delayForSeconds(1); - calculateLoot = (startingPeasantShips *100) + randomValue.nextInt(startingPeasantShips) *200; - player.setMoney(player.getMoney() + calculateLoot); - System.out.printf("We got $%,d!", calculateLoot); - delayForSeconds(2); - return true; - } else if (exitValue == 2) { - player.gameOver(); - return true; - } else if (exitValue == 3) { - System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); - delayForSeconds(2); - return true; - } - return false; - - - } - -} diff --git a/src/ShipWarfareGUI.java b/src/ShipWarfareGUI.java index f028417..5280e30 100644 --- a/src/ShipWarfareGUI.java +++ b/src/ShipWarfareGUI.java @@ -15,7 +15,6 @@ public class ShipWarfareGUI { private Player player = new Player(); - private ShipWarfare shipWarfare = new ShipWarfare(player); private HBox hBox; private Button fightButton; private Button runButton; diff --git a/src/Start.java b/src/Start.java deleted file mode 100644 index 8a86938..0000000 --- a/src/Start.java +++ /dev/null @@ -1,79 +0,0 @@ -import java.util.Scanner; -public class Start -{ - private Player player; - - /** - * gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes. - * - * @return playerDummy -- playerDummy is a copy of the player instance variable. - */ - public Player getPlayer() { - Player playerTemp = new Player(player); - return playerTemp; - } - - /** - * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes. - * - * @param player is a Player object that will replace the current instance of the player instance variable. - */ - public void setPlayer(Player player) { - Player playerTemp = new Player(player); - this.player = playerTemp; - } - - /** - * Asks the user to input the name that they would like to be called in the game - * - * @param name the name that you would like to be called in the game - */ - public void setFirm (String name) { - if (name.length() <= 22) { - player.setName(name); - } - } - - /** - * Initializes the game by asking for your name and if you would like to start with either: 1) money and a debt or - * 2) guns and no cash/debt. - */ - public void initialize() - { - Scanner userInput = new Scanner(System.in); - System.out.println("Taipan, \nWhat will you name your firm:"); - setFirm(userInput.nextLine()); - System.out.println("Do you want to start . . .\n\t1) With cash (and a debt)\n\t\t\t>> or <<\n\t" + - "2) With five guns and no cash (But no debt!)?\n "); - int input = userInput.nextInt(); - if (input == 1) - { - player.setMoney(400); - player.setDebt(5000); - - } - if (input == 2) - { - player.setGuns(5); - } - // purely for testing purposes. - if(player.getName().equalsIgnoreCase("Vikram")){ - player.setMoney(999999999); - player.setBank(999999999); - player.setGuns(999); - player.setHP(99999999); - player.setCargoSpace(99999999); - } - } - - - /** - * Copy constructor. - * @param player object of the class Player - */ - public Start(Player player) - { - Player playerTemp = new Player(player); - this.player = playerTemp; - } -} diff --git a/src/TaipanShop.java b/src/TaipanShop.java deleted file mode 100644 index e1c0399..0000000 --- a/src/TaipanShop.java +++ /dev/null @@ -1,785 +0,0 @@ -import java.util.Random; -import java.util.Scanner; -import javafx.application.Application; -import javafx.geometry.Insets; -import javafx.scene.Scene; -import javafx.scene.control.Label; -import javafx.scene.layout.GridPane; -import javafx.scene.layout.HBox; -import javafx.stage.Stage; -public class TaipanShop extends Application { - - public static void main(String args[]){ - launch(args); - } - public void start(Stage stage){ - stage.setTitle("Shop"); - - GridPane grid = new GridPane(); - grid.setPadding(new Insets(10,10,10,10)); - grid.setVgap(20); - grid.setHgap(20); - - grid.add(new Label("Firm: "+ player.getName()), 2, 0); - - HBox warehouse = new HBox(); - warehouse.setSpacing(20); - int itemsInWarehouse = player.getwOpium()+player.getwGeneral()+player.getwArms()+player.getwSilk(); - Label ware1 = new Label("Warehouse\n\tOpium\n\tSilk\n\tArms\n\tGeneral"); - Label ware2 = new Label("\n"+player.getwOpium()+"\n"+player.getwSilk()+"\n"+player.getwArms()+"\n"+player.getwGeneral()); - Label ware3 = new Label("\nIn use:\n " + itemsInWarehouse + "\nVacant:\n " + (10000 - itemsInWarehouse)); - warehouse.getChildren().addAll(ware1, ware2, new Label(), ware3); - - HBox inventory = new HBox(); - inventory.setSpacing(20); - int itemsInInventory = player.getCargoSpace()-player.getSilkHeld()-player.getOpiumHeld()-player.getGeneralHeld()-player.getArmsHeld(); - Label inv1 = new Label("Hold "+itemsInInventory+"\n\tOpium\n\tSilk\n\tArms\n\tGeneral"); - Label inv2 = new Label("\n"+player.getOpiumHeld()+"\n"+player.getSilkHeld()+"\n"+player.getArmsHeld()+"\n"+player.getGeneralHeld()); - Label inv3 = new Label("Guns "+player.getGuns()); - inventory.getChildren().addAll(inv1, inv2, new Label(), inv3); - - String location; - switch(player.getLocation()){ - case 1: location = "Hong Kong"; break; - case 2: location = "Shanghai"; break; - case 3: location = "Nagasaki"; break; - case 4: location = "Saigon"; break; - case 5: location = "Manila"; break; - case 6: location = "Singapore"; break; - case 7: location = "Batavia"; break; - default: location = "Error"; break; - } - - grid.add(warehouse, 1, 1); - grid.add(inventory, 1, 2); - grid.add(new Label("\n\n\n Location\n"+location),3, 1 ); - grid.add(new Label("Debt\n"+player.getDebt()), 3, 2); - - Scene root = new Scene(grid, 600, 480); - stage.setResizable(false); - stage.setScene(root); - stage.show(); - } - - private Player player; - private int opiumPrice = 16000; - private int silkPrice = 1600; - private int armsPrice = 160; - private int generalPrice = 8; - - /** - * This method is evoked if the user is eligible to win, and chooses to end the game (by winning). - */ - public void retire(){ - player.setRetire(true); - System.out.println("You win!"); - System.exit(0); - } - - /** - * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes. - * - * @param player is a Player object that will replace the current instance of the player instance variable. - */ - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes. - * - * @return playerDummy -- playerDummy is a copy of the player instance variable. - */ - public Player getPlayer(){ - Player playerDummy = new Player(player); - return playerDummy; - } - - /** - * constructor; only runs when a Player object is provided. The constructor is fully encapsulated. - * - * @param player is a Player object that will be copied and the player instance variable is set to the copy. - */ - public TaipanShop(Player player){ - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * getter for opiumPrice instance variable. - * - * @return opiumPrice -- the price of opium in the shop - */ - public int getOpiumPrice() { - return opiumPrice; - } - - /** - * setter for the opiumPrice instance variable. Runs as long as the parameter is greater than 0. - * - * @param opiumPrice -- what the instance variable opiumPrice should be changed to. - */ - public void setOpiumPrice(int opiumPrice) { - if(opiumPrice > 0){ - this.opiumPrice = opiumPrice; - } - } - - /** - * getter for silkPrice instance variable. - * - * @return silkPrice -- the price of silk in the shop. - */ - public int getSilkPrice() { - return silkPrice; - } - - /** - * setter for the silkPrice instance variable. Runs as long as the parameter is greater than 0. - * - * @param silkPrice -- what the instance variable silkPrice should be changed to. - */ - public void setSilkPrice(int silkPrice) { - if(silkPrice > 0){ - this.silkPrice = silkPrice; - } - } - - /** - * getter for armsPrice instance variable. - * - * @return armsPrice -- the price of arms in the shop. - */ - public int getArmsPrice() { - return armsPrice; - } - - /** - * setter for the armsPrice instance variable. Runs as long as the parameter is greater than 0. - * - * @param armsPrice -- what the instance variable armsPrice should be changed to. - */ - public void setArmsPrice(int armsPrice) { - if(armsPrice > 0){ - this.armsPrice = armsPrice; - } - } - - /** - * getter for generalPrice instance variable. - * - * @return generalPrice -- the price of general cargo in the shop. - */ - public int getGeneralPrice() { - return generalPrice; - } - - /** - * setter for the generalPrice instance variable. Runs as long as the parameter is greater than 0. - * - * @param generalPrice -- what the instance variable generalPrice should be changed to. - */ - public void setGeneralPrice(int generalPrice) { - if(generalPrice > 0){ - this.generalPrice = generalPrice; - } - } - - /** - * this method is evoked if the user has decided to travel elsewhere. - */ - public void travel(){ - Travel travel = new Travel(player); - travel.travelTo(); - player = travel.getPlayer(); - } - - /** - * this method is evoked if the user wants to use the warehouse to store items or take items out. - */ - public void warehouse(){ - Warehouse warehouse = new Warehouse(player); - warehouse.changeWarehouse(); - player = warehouse.getPlayer(); - } - - /** - * this method is evoked if the user wants to use the bank to deposit or withdraw money. - */ - public void bank(){ - Bank bank = new Bank(player); - bank.bank(); - player = bank.getPlayer(); - } - - /** - * this method is evoked if the user wants to use get a loan or pay a loan off. - */ - public void loan(){ - loanShark loan = new loanShark(player); - loan.loanMoney(); - player = loan.getPlayer(); - } - - /** - * this method is when the shop is accessed, randomizing the prices of all the items. - */ - public void updatePrices(){ - String s = "\n" + player.getName() + ", the price of "; - double value = 80*Math.random(); - Random rand = new Random(); - opiumPrice = (rand.nextInt(201) + 60)*100; - silkPrice = (rand.nextInt(201) + 60)*10; - armsPrice = (rand.nextInt(21) + 6)*10; - generalPrice = rand.nextInt(17) + 4; - - // there is a 10% chance that the price of an item is increased/decreased beyond its regular range. - if(value < 8){ - if(value < 2){ - if(value < 1){ - opiumPrice /= 5; - System.out.println(s + "Opium has dropped to " + opiumPrice +"!!!\n"); - }else{ - opiumPrice *= 5; - System.out.println(s + "Opium has risen to " + opiumPrice +"!!!\n"); - } - }else if(value < 4){ - if(value < 3){ - silkPrice /= 5; - System.out.println(s + "Silk has dropped to " + silkPrice +"!!!\n"); - }else{ - silkPrice *= 5; - System.out.println(s + "Silk has risen to " + silkPrice +"!!!\n"); - } - }else if(value < 6){ - if(value < 3){ - armsPrice /= 5; - System.out.println(s + "Arms has dropped to " + armsPrice +"!!!\n"); - }else{ - armsPrice *= 5; - System.out.println(s + "Arms has risen to " + armsPrice +"!!!\n"); - } - }else{ - if(value < 7){ - generalPrice = 1; - System.out.println(s + "General Cargo has dropped to 1!!!\n"); - }else{ - generalPrice *= 5; - System.out.println(s + "General Cargo has risen to " + generalPrice + "!!!\n"); - } - } - } - } - - /** - * this method prints the shop UI and the player's inventory and status. - */ - public void printShop(){ - int currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld(); - if(player.getCargoSpace() - currentCargo < 0){ - System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%"); - }else{ - System.out.println("Hold: " + (player.getCargoSpace()-currentCargo) + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%"); - } - System.out.println("-------------------------------------------------------------"); - System.out.println(" Opium: " + player.getOpiumHeld() + " Silk: " + player.getSilkHeld()); - System.out.println(" Arms: " + player.getArmsHeld() + " General: " + player.getGeneralHeld()); - System.out.println("-------------------------------------------------------------"); - System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+ " Debt: " + player.getDebt()+"\n"); - System.out.println(player.getName() + ", present prices per unit here are:"); - System.out.println(" Opium: " + opiumPrice + " Silk: " + silkPrice); - System.out.println(" Arms: " + armsPrice + " General: " + generalPrice); - } - - /** - * This method is evoked if the user is at the location one port. - */ - public void atLocationOne(){ - boolean notDone = true; - Scanner input = new Scanner(System.in); - - // as long as the user does not enter a valid input, the code will run in a loop forever. - while(notDone){ - printShop(); - System.out.println("\nShall I Buy, Sell, Visit Bank, Get Loans, Transfer Cargo, or Quit Trading?"); - String response = input.next(); - if (response.equalsIgnoreCase("B")) { - boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + player.getName() + "?"); - - // when buying an item, the user must have the right amount of money, and buy non-negative amounts. - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / opiumPrice && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()+num); - player.setMoney(player.getMoney()-num * opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / silkPrice && num >= 0) { - player.setSilkHeld(player.getSilkHeld()+num); - player.setMoney(player.getMoney()-num * silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / armsPrice && num >= 0) { - player.setArmsHeld(player.getArmsHeld()+num); - player.setMoney(player.getMoney() - num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / generalPrice && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()+num); - player.setMoney(player.getMoney() - num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - - } // when selling, the user must enter a non-negative amount of items, and not more than what they have. - else if (response.equalsIgnoreCase("S")) { - boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + player.getName() + "?"); - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getOpiumHeld() && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()-num); - player.setMoney(player.getMoney() + num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getSilkHeld() && num >= 0) { - player.setSilkHeld(player.getSilkHeld()-num); - player.setMoney(player.getMoney() + num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getArmsHeld() && num >= 0) { - player.setArmsHeld(player.getArmsHeld()-num); - player.setMoney(player.getMoney() + num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getGeneralHeld() && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()-num); - player.setMoney(player.getMoney() + num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - - } else if (response.equalsIgnoreCase("V")) { - bank(); - } else if (response.equalsIgnoreCase("T")) { - warehouse(); - }else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { - loan(); - } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop. - else if (response.equalsIgnoreCase("Q")) { - travel(); - notDone = false; - } - } - } - - /** - * This method is evoked when the user is at any port other than location one. - */ - public void notAtLocationOne(){ - boolean notDone = true; - Scanner input = new Scanner(System.in); - - // as long as the user does not enter a valid input, the code will run in a loop forever. - while(notDone){ - printShop(); - System.out.println("\nShall I Buy, Sell, or Quit Trading?"); - String response = input.next(); - if (response.equalsIgnoreCase("B")) { - boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + player.getName() + "?"); - - // when buying an item, the user must have the right amount of money, and buy non-negative amounts. - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / opiumPrice && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()+num); - player.setMoney(player.getMoney() - num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / silkPrice && num >= 0) { - player.setSilkHeld(player.getSilkHeld()+num); - player.setMoney(player.getMoney() - num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / armsPrice && num >= 0) { - player.setArmsHeld(player.getArmsHeld()+num); - player.setMoney(player.getMoney() - num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / generalPrice && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()+num); - player.setMoney(player.getMoney() - num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - - } // when selling, the user must enter a non-negative amount of items, and not more than what they have. - else if (response.equalsIgnoreCase("S")) { - boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + player.getName() + "?"); - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getOpiumHeld() && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()-num); - player.setMoney(player.getMoney() + num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getSilkHeld() && num >= 0) { - player.setSilkHeld(player.getSilkHeld()-num); - player.setMoney(player.getMoney() + num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getArmsHeld() && num >= 0) { - player.setArmsHeld(player.getArmsHeld()-num); - player.setMoney(player.getMoney() + num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getGeneralHeld() && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()-num); - player.setMoney(player.getMoney() + num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); - } - } - } - } - } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop. - else if (response.equalsIgnoreCase("Q")) { - travel(); - notDone = false; - } - } - } - - /** - * this method is run if the user is eligible to win, and is at location one. - */ - public void retireAndLocationOne(){ - boolean notDone = true; - Scanner input = new Scanner(System.in); - - // as long as the user does not enter a valid input, the code will run in a loop forever. - while(notDone){ - printShop(); - System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Get Loans, Retire, or Quit Trading?"); - String response = input.next(); - if (response.equalsIgnoreCase("B")) { - boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + player.getName() + "?"); - - // when buying an item, the user must have the right amount of money, and buy non-negative amounts. - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / opiumPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / opiumPrice && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()+num); - player.setMoney(player.getMoney()-num * opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / silkPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / silkPrice && num >= 0) { - player.setSilkHeld(player.getSilkHeld()+num); - player.setMoney(player.getMoney()-num * silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / armsPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / armsPrice && num >= 0) { - player.setArmsHeld(player.getArmsHeld()+num); - player.setMoney(player.getMoney() - num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I buy, " + player.getName() + "? (You can afford " + player.getMoney() / generalPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getMoney() / generalPrice && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()+num); - player.setMoney(player.getMoney() - num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you can't afford that!"); - } else { - System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); - } - } - } - } - - } // when selling, the user must enter a non-negative amount of items, and not more than what they have. - else if (response.equalsIgnoreCase("S")) { - boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + player.getName() + "?"); - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getOpiumHeld() && num >= 0) { - player.setOpiumHeld(player.getOpiumHeld()-num); - player.setMoney(player.getMoney() + num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getSilkHeld() && num >= 0) { - player.setSilkHeld(player.getSilkHeld()-num); - player.setMoney(player.getMoney() + num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getArmsHeld() && num >= 0) { - player.setArmsHeld(player.getArmsHeld()-num); - player.setMoney(player.getMoney() + num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= player.getGeneralHeld() && num >= 0) { - player.setGeneralHeld(player.getGeneralHeld()-num); - player.setMoney(player.getMoney() + num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(player.getName() + ", you don't have that many to sell!"); - } else { - System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - - } else if (response.equalsIgnoreCase("V")) { - bank(); - } else if (response.equalsIgnoreCase("T")) { - warehouse(); - } else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { - loan(); - } // if the user wishes to quit trading, they may do so. Doing this breaks them out of the loop. - else if (response.equalsIgnoreCase("Q")) { - travel(); - notDone = false; - } // if the user wishes to retire and win the game, they may do so. Doing this breaks them out of the loop. - else if (response.equalsIgnoreCase("R")) { - retire(); - notDone = false; - } - } - } - - /** - * the general method that utilizes all the other methods to form a fully functioning shop. - */ - public void shop() { - updatePrices(); - - // first case is triggered if the user is at location one, and has less than $1 million net worth - if (player.getLocation() == 1 && player.getBank()+player.getMoney()-player.getDebt() < 1000000) { - atLocationOne(); - } // the second case is triggered if the user is at a location other than location one. - else if(player.getLocation() != 1) { - notAtLocationOne(); - } // the last case is triggered when the other conditions are not met; it is triggered when the user has a net - // worth that is greater than or equal to $1 million and is at location one. - else{ - retireAndLocationOne(); - } - } -} diff --git a/src/TaipanShopGUI.java b/src/TaipanShopGUI.java index 3e38509..b529b53 100644 --- a/src/TaipanShopGUI.java +++ b/src/TaipanShopGUI.java @@ -271,7 +271,7 @@ public class TaipanShopGUI { buyButton.setVisible(true); sellButton.setVisible(true); bankButton.setVisible(true); - cargoButton.setVisible(true); + cargoButton.setVisible(false); loanButton.setVisible(true); quitButton.setVisible(true); opiumButton.setVisible(false); @@ -284,7 +284,7 @@ public class TaipanShopGUI { buyButton.setVisible(true); sellButton.setVisible(true); bankButton.setVisible(true); - cargoButton.setVisible(true); + cargoButton.setVisible(false); loanButton.setVisible(true); numberInput.setVisible(false); quitButton.setVisible(true); diff --git a/src/Travel.java b/src/Travel.java deleted file mode 100644 index 73035ec..0000000 --- a/src/Travel.java +++ /dev/null @@ -1,174 +0,0 @@ -import java.util.Random; -import java.util.Scanner; - -public class Travel { - - private Player player; - - /** - * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes. - * - * @param player is a Player object that will replace the current instance of the player instance variable. - */ - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * getter method for obtaining a player object. - * - * @return returns player object - */ - public Player getPlayer() { - Player playerDummy = new Player(player); - return playerDummy; - } - - /** - * constructor; only runs when a Player object is provided. The constructor is fully encapsulated. - * - * @param player is a Player object that will be copied and the player instance variable is set to the copy. - */ - public Travel(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * When provided a location number: the method returns a print statement stating the location's name and call another - * method to change the location of the Player object. - * - * @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy. - */ - private void seaAtlas(int locationOfTravel) { - switch (locationOfTravel) { - case 1: - System.out.println("\nArriving at Hong Kong"); - player.setLocation(1); - break; - case 2: - System.out.println("\nArriving at Shanghai"); - player.setLocation(2); - break; - case 3: - System.out.println("\nArriving at Nagasaki"); - player.setLocation(3); - break; - case 4: - System.out.println("\nArriving at Saigon"); - player.setLocation(4); - break; - case 5: - System.out.println("\nArriving at Manila"); - player.setLocation(5); - break; - case 6: - System.out.println("\nArriving at Singapore"); - player.setLocation(6); - break; - case 7: - System.out.println("\nArriving at Batavia"); - player.setLocation(7); - break; - } - } - - /** - * Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing. - * - * @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed - * by a typhoon. - **/ - private void randomEventSea(int locationOfTravel) throws Exception { - Random rand = new Random(); - int randGenNum = rand.nextInt(3) + 1; - if (randGenNum == 1) { - peasantFleet(); - }else if (randGenNum == 2) { - disaster(locationOfTravel); - System.out.println("We made it!"); - } - } - - /** - * Based on random chance either throws the player character off course, or continues them on their way to their - * destination. - * - * @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed - * by a typhoon. - **/ - private void disaster(int locationOfTravel) { - //Tells player that there is a storm approaching. - System.out.print("Storm " + player.getName() + "! "); - Random rand = new Random(); - int randGenNum = rand.nextInt(5) + 1; - - //If the player lands within this range, nothing happens to them - //Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel). - if (randGenNum <= 2) { - System.out.println(" We made it through!"); - }else { - while (randGenNum == locationOfTravel) { - randGenNum = rand.nextInt(7) + 1; - if (randGenNum != locationOfTravel) { - System.out.println("We've been blown off course!"); - seaAtlas(randGenNum); - } - } - } - } - - /** - * To use the peasant fleet class while still maintaining encapsulation we have to create a ShipWarefare object and - * run the method from there. After the method has been run we can update the player object in this class. - * @throws Exception throws Exception so that we can use the time library to make the player if we want to. - **/ - public void peasantFleet() throws Exception { - ShipWarfare attackShip = new ShipWarfare(player); - attackShip.peasantFleetAttack(); - player = attackShip.getPlayer(); - } - - /** - *Used to travel between different areas inside of the game world. - * If the player's inventory is too full it won't run. - * Also calculates loan and bank interest between the jumps between islands. - **/ - public void travelTo() { - Scanner keyboard = new Scanner(System.in); - String response; - int tempInt; - boolean hasTraveled = false; - - //Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory. - if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){ - while (true) { - System.out.println("\n" + player.getName() + ", do you wish to go to:\n"); - System.out.println("1) Hong Kong, 2) Shanghai, 3) Nagasaki,\n4) Saigon, 5) Manila, 6) Singapore, or 7) Batavia?"); - - response = keyboard.nextLine(); - //Just in case the player types something that was not intended. It will refresh the question and ask it again - try { - tempInt = Integer.parseInt(response); - //Makes sure you can't travel to your own location. - if (tempInt != player.getLocation()) { - randomEventSea(tempInt); - seaAtlas(tempInt); - hasTraveled = true; - player.setBank((int) (player.getBank() * 1.01)); - player.setDebt((int) (player.getDebt() * 1.01)); - } else System.out.println("\nYou're already here " + player.getName() + "."); - } catch (Exception e) { - System.out.print("\nSorry, " + player.getName() + " could you say that again?"); - } - if (hasTraveled) { - break; - } - } - } - else{ - System.out.println(player.getName() + " the cargo is too heavy! We can't set sail!"); - } - } -} diff --git a/src/Warehouse.java b/src/Warehouse.java deleted file mode 100644 index b4f7d0b..0000000 --- a/src/Warehouse.java +++ /dev/null @@ -1,272 +0,0 @@ -import java.util.Scanner; - -/** - * The purpose of this class is to create a warehouse where the goods - * can be safely stored without holing space on the ship! - */ -public class Warehouse { - /*private int wOpium = 0; - private int wSilk = 0; - private int wGeneral = 0; - private int wArms = 0;*/ - private Player player; - - /** - * setter method that takes in a Player object as an argument. - * - * @param player object of the class Player - */ - - public void setPlayer(Player player) { - Player playerDumy = new Player(player); - this.player = playerDumy; - } - - /** - * getter method for obtaining a player object. - * - * @return returns player object - */ - - public Player getPlayer() { - Player playerDummy = new Player(player); - return playerDummy; - } - - /** - * Class Constructor that takes in a type player as a parameter - * - * @param player object of the class Player - */ - - public Warehouse(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * This method adds an amount of a certain good - * the user is prompted to enter the amount they would like to - * add followed by the good they would like to add to the warehouse. - * the method checks if the player has sufficient goods to transfer, and if the player does - * then the method executes the transfer - * - */ - public void addAmount() { - boolean askGood = false; - String amount; - int finalAmount = 0; - System.out.println("Please enter the amount of the good you would like to ADD."); - Scanner keyboard = new Scanner(System.in); - amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add - /*The try function ensures that the program does not crash - due to any errors while giving the program an incorrect input*/ - try { - //The if statement checks that you have enough resources to make the transfer - if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) { - finalAmount = Integer.parseInt(amount); - askGood = true; - } - //Else statement lets the user know that they do not hav enough goods to make the requested transfer - else { - System.out.println("Nice try but you don't have any items of that quantity!"); - askGood = false; - } - //Ensures that goods are only transferred if they have the specified amount - //The user is prompted to enter which good they want to transfer - if (askGood == true) { - String good; - System.out.println("Please enter a good to transfer O, S, G, A :"); - good = keyboard.nextLine(); - int held = 0; - //The following set of loops check to see which good the user has selected and makes the transfer - if (Integer.parseInt(amount) > 0) { - if (good.equalsIgnoreCase("O")) { - if (player.getOpiumHeld() >= Integer.parseInt(amount)) { - player.setwOpium(player.getwOpium() + finalAmount); - held = player.getOpiumHeld(); - player.setOpiumHeld(held - finalAmount); - System.out.println(player.getOpiumHeld()); - } else { - System.out.println("You don't even have that much opium!"); - } - } else if (good.equalsIgnoreCase("S")) { - if (player.getSilkHeld() >= Integer.parseInt(amount)) { - player.setwSilk(player.getwSilk() + finalAmount); - held = player.getSilkHeld(); - player.setSilkHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much silk!"); - - } - } else if (good.equalsIgnoreCase("G")) { - if (player.getGeneralHeld() >= Integer.parseInt(amount)) { - player.setwGeneral(player.getwGeneral() + finalAmount); - held = player.getGeneralHeld(); - player.setGeneralHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much general cargo!"); - - } - } else if (good.equalsIgnoreCase("A")) { - if (player.getArmsHeld() >= Integer.parseInt(amount)) { - player.setwArms(player.getwArms() + finalAmount); - held = player.getArmsHeld(); - player.setArmsHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much Arms!"); - } - } - } - //Ensures no negative amounts are entered - else { - System.out.println("Sorry this transfer cannot be made"); - } - } - //If the program errors out this is the message displayed and the method is re-run, so that the game does not end. - } catch (Exception e) { - System.out.println("Wait, that's not a valid input please try again"); - } - } - - /** - * This method removes an amount of a certain good - * the user is prompted to enter the amount they would like to - * remove followed by the good they would like to remove from the warehouse. - * the method checks if the player has sufficient goods to transfer, and if the player does - * then the method executes the transfer - * - */ - - public void removeAmount() { - String amount; - boolean askGood = false; - int finalAmount = 0; - System.out.println("Please enter the amount of the good you would like to REMOVE"); - Scanner keyboard = new Scanner(System.in); - //Prompts the user for the amount they would like to remove - amount = keyboard.nextLine(); - //The if statement checks that you have enough resources to make the transfer - try { - //The if statement checks that you have enough resources to make the transfer - if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) { - finalAmount = Integer.parseInt(amount); - askGood = true; - } - //Else statement lets the user know that they do not hav enough goods to make the requested transfer - else { - System.out.println("Nice try but you don't have any items of that quantity in the warehouse!"); - askGood = false; - } - - //Ensures that goods are only transferred if they have the specified amount - //The user is prompted to enter which good they want to transfer - - if (askGood == true) { - String good; - System.out.println("Please enter a good to transfer O, S, G, A :"); - good = keyboard.nextLine(); - int held = 0; - //The following set of loops check to see which good the user has selected and makes the transfer and amount > 0 - if (Integer.parseInt(amount) > 0) { - if (good.equalsIgnoreCase("O")) { - if (player.getwOpium() >= Integer.parseInt(amount)) { - player.setwOpium(player.getwOpium() - Integer.parseInt(amount)); - held = player.getOpiumHeld(); - player.setOpiumHeld(held + finalAmount); - } else { - System.out.println("You don't have that much opium stored in the warehouse!"); - } - } else if (good.equalsIgnoreCase("S")) { - if (player.getwSilk() >= Integer.parseInt(amount)) { - player.setwSilk(player.getwSilk() - Integer.parseInt(amount)); - held = player.getSilkHeld(); - player.setSilkHeld(held + finalAmount); - } else { - System.out.println("You don't have that much silk stored in the warehouse!"); - } - } else if (good.equalsIgnoreCase("G")) { - if (player.getwGeneral() >= Integer.parseInt(amount)) { - player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount)); - held = player.getGeneralHeld(); - player.setGeneralHeld(held + finalAmount); - } else { - System.out.println("You don't have that much general cargo stored in the warehouse!"); - - } - } else if (good.equalsIgnoreCase("A")) { - if (player.getwArms() >= Integer.parseInt(amount)) { - player.setwArms(player.getwArms() - Integer.parseInt(amount)); - held = player.getArmsHeld(); - player.setArmsHeld(held + finalAmount); - } else { - System.out.println("You don't have that much arms stored in the warehouse!"); - - } - } - } - //Ensures the value entered is positive - else { - System.out.println("Sorry this transfer cannot be made"); - } - } - } - //If the program errors out this is the message displayed and the method is re-run, so that the game does not end. - catch (Exception e){ - System.out.println("Wait, that's not a valid input please try again"); - } - } - - /** - * This method prints the stock that is in the warehouse currently using the get and set - * methods from the player class. This is to allow the user to be able to know how much they have - * stored in the warehouse - */ - public void showWarehouse() { - System.out.println("--------------------\nWarehouse\n--------------------"); - System.out.println("Opium : " + player.getwOpium()); - System.out.println("Silk : " + player.getwSilk()); - System.out.println("General : " + player.getwGeneral()); - System.out.println("Arms : " + player.getwArms()); - } - - /** - * This method combines the add and remove methods and prompts the user to - * enter what they would like to do. Add or remove and accordingly invokes - * the required methods - */ - public void changeWarehouse() { - boolean keepGoing = true; - while (keepGoing) { - this.showWarehouse(); - String input = " "; - System.out.println("Would you like to add(A) or remove(R) resources? "); - Scanner keyboard = new Scanner(System.in); - input = keyboard.next(); - if (input.equalsIgnoreCase("R")) { - this.removeAmount(); - this.showWarehouse(); - } else if (input.equalsIgnoreCase("A")) { - this.addAmount(); - this.showWarehouse(); - - } - else{ - System.out.println("Don't waste the warehouse's time, try again later with a valid input"); - } - - String check; - //Check to see if the player wants to continue in the warehouse or they are done - System.out.println("Would you like to do any other business? Y / N?"); - check = keyboard.nextLine(); - check = keyboard.nextLine(); - - if (check.equalsIgnoreCase("Y")) { - keepGoing = true; - } else if (check.equalsIgnoreCase("N")) { - keepGoing = false; - } - } - } - -} diff --git a/src/WarehouseGUI.java b/src/WarehouseGUI.java index 31c4f3a..ab6c432 100644 --- a/src/WarehouseGUI.java +++ b/src/WarehouseGUI.java @@ -149,6 +149,7 @@ public class WarehouseGUI { title.setFont(new Font(24.0)); borderPane.setTop(title); + /** * creates an HBox at the center of the borderpane with a width of 200 and height of 100. * @@ -164,9 +165,8 @@ public class WarehouseGUI { */ withdraw.setContentDisplay(javafx.scene.control.ContentDisplay.CENTER); withdraw.setMnemonicParsing(false); - withdraw.setPrefWidth(250.0); withdraw.setText("Withdraw"); - + updateLabels(); withdraw.setOnAction(new EventHandler() { /** * Creates a button with text "Deposit" which handles user events. @@ -174,7 +174,9 @@ public class WarehouseGUI { */ @Override public void handle(ActionEvent event) { + int withdraw = Integer.parseInt(textIn.getText()); + updateLabels(); if(opium.isSelected()){ if (player.getwOpium() >= withdraw) { player.setwOpium(player.getwOpium() - withdraw); @@ -183,23 +185,78 @@ public class WarehouseGUI { title.setText("You don't have that much opium stored in the warehouse!"); } } + if(silk.isSelected()){ + if (player.getwSilk() >= withdraw) { + player.setwSilk(player.getwSilk() - withdraw); + player.setSilkHeld(player.getSilkHeld() + withdraw); + } else { + title.setText("You don't have that much silk stored in the warehouse!"); + } + } + if(arms.isSelected()){ + if (player.getwArms() >= withdraw) { + player.setwArms(player.getwArms() - withdraw); + player.setArmsHeld(player.getArmsHeld() + withdraw); + } else { + title.setText("You don't have that much arms stored in the warehouse!"); + } + } + if(general.isSelected()){ + if (player.getwGeneral() >= withdraw) { + player.setwGeneral(player.getwGeneral() - withdraw); + player.setGeneralHeld(player.getGeneralHeld() + withdraw); + } else { + title.setText("You don't have that much general stored in the warehouse!"); + } + } } } ); deposit.setMnemonicParsing(false); - deposit.setPrefWidth(250.0); deposit.setText("Deposit"); deposit.setTextAlignment(javafx.scene.text.TextAlignment.CENTER); borderPane.setBottom(hBox); deposit.setOnAction(new EventHandler() { - @Override - public void handle(ActionEvent event) { - int deposit = Integer.parseInt(textIn.getText()); - } - } - ); + @Override + public void handle(ActionEvent event) { + updateLabels(); + int deposit = Integer.parseInt(textIn.getText()); + if (opium.isSelected()) { + if (player.getOpiumHeld() >= deposit) { + player.setwOpium(player.getwOpium() + deposit); + player.setOpiumHeld(player.getOpiumHeld() - deposit); + } else { + title.setText("You don't have that much opium stored in the ship!"); + } + } + if (silk.isSelected()) { + if (player.getwSilk() >= deposit) { + player.setwSilk(player.getwSilk() + deposit); + player.setSilkHeld(player.getSilkHeld() - deposit); + } else { + title.setText("You don't have that much silk stored in the ship!"); + } + } + if (arms.isSelected()) { + if (player.getwArms() >= deposit) { + player.setwArms(player.getwArms() + deposit); + player.setArmsHeld(player.getArmsHeld() - deposit); + } else { + title.setText("You don't have that much arms stored in the ship!"); + } + } + if (general.isSelected()) { + if (player.getwGeneral() >= deposit) { + player.setwGeneral(player.getwGeneral() + deposit); + player.setGeneralHeld(player.getGeneralHeld() - deposit); + } else { + title.setText("You don't have that much general stored in the ship!"); + } + } + } + }); splitMenu.setMnemonicParsing(false); splitMenu.setText("Item"); @@ -549,6 +606,8 @@ public class WarehouseGUI { stage.setTitle("Warehouse"); stage.setResizable(false); stage.setScene(root); + updateLabels(); + return stage; } @@ -567,272 +626,15 @@ public class WarehouseGUI { * The purpose of this class is to create a warehouse where the goods * can be safely stored without holing space on the ship! */ + public void updateLabels(){ + generalPlayer.setText("General: " + player.getGeneralHeld()); + armsPlayer.setText("Arms: " + player.getArmsHeld()); + silkPlayer.setText("Silk: " + player.getSilkHeld()); + opiumPlayer.setText("Opium: " + player.getOpiumHeld()); - public class Warehouse { - /*private int wOpium = 0; - private int wSilk = 0; - private int wGeneral = 0; - private int wArms = 0;*/ - private Player player; - - /** - * setter method that takes in a Player object as an argument. - * - * @param player object of the class Player - */ - - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * getter method for obtaining a player object. - * - * @return returns player object - */ - - public Player getPlayer() { - Player playerDummy = new Player(player); - return playerDummy; - } - - /** - * Class Constructor that takes in a type player as a parameter - * - * @param player object of the class Player - */ - - public Warehouse(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * This method adds an amount of a certain good - * the user is prompted to enter the amount they would like to - * add followed by the good they would like to add to the warehouse. - * the method checks if the player has sufficient goods to transfer, and if the player does - * then the method executes the transfer - * - */ - public void addAmount() { - boolean askGood = false; - String amount; - int finalAmount = 0; - System.out.println("Please enter the amount of the good you would like to ADD."); - Scanner keyboard = new Scanner(System.in); - amount = keyboard.nextLine();//Asks the user for the amount of the good they would like to add - /*The try function ensures that the program does not crash - due to any errors while giving the program an incorrect input*/ - try { - //The if statement checks that you have enough resources to make the transfer - if (Integer.parseInt(amount) <= player.getOpiumHeld() || Integer.parseInt(amount) <= player.getSilkHeld() || Integer.parseInt(amount) <= player.getGeneralHeld() || Integer.parseInt(amount) <= player.getArmsHeld()) { - finalAmount = Integer.parseInt(amount); - askGood = true; - } - //Else statement lets the user know that they do not hav enough goods to make the requested transfer - else { - System.out.println("Nice try but you don't have any items of that quantity!"); - askGood = false; - } - //Ensures that goods are only transferred if they have the specified amount - //The user is prompted to enter which good they want to transfer - if (askGood == true) { - String good; - System.out.println("Please enter a good to transfer O, S, G, A :"); - good = keyboard.nextLine(); - int held = 0; - //The following set of loops check to see which good the user has selected and makes the transfer - if (Integer.parseInt(amount) > 0) { - if (good.equalsIgnoreCase("O")) { - if (player.getOpiumHeld() >= Integer.parseInt(amount)) { - player.setwOpium(player.getwOpium() + finalAmount); - held = player.getOpiumHeld(); - player.setOpiumHeld(held - finalAmount); - System.out.println(player.getOpiumHeld()); - } else { - System.out.println("You don't even have that much opium!"); - } - } else if (good.equalsIgnoreCase("S")) { - if (player.getSilkHeld() >= Integer.parseInt(amount)) { - player.setwSilk(player.getwSilk() + finalAmount); - held = player.getSilkHeld(); - player.setSilkHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much silk!"); - - } - } else if (good.equalsIgnoreCase("G")) { - if (player.getGeneralHeld() >= Integer.parseInt(amount)) { - player.setwGeneral(player.getwGeneral() + finalAmount); - held = player.getGeneralHeld(); - player.setGeneralHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much general cargo!"); - - } - } else if (good.equalsIgnoreCase("A")) { - if (player.getArmsHeld() >= Integer.parseInt(amount)) { - player.setwArms(player.getwArms() + finalAmount); - held = player.getArmsHeld(); - player.setArmsHeld(held - finalAmount); - } else { - System.out.println("You don't even have that much Arms!"); - } - } - } - //Ensures no negative amounts are entered - else { - System.out.println("Sorry this transfer cannot be made"); - } - } - //If the program errors out this is the message displayed and the method is re-run, so that the game does not end. - } catch (Exception e) { - System.out.println("Wait, that's not a valid input please try again"); - } - } - - /** - * This method removes an amount of a certain good - * the user is prompted to enter the amount they would like to - * remove followed by the good they would like to remove from the warehouse. - * the method checks if the player has sufficient goods to transfer, and if the player does - * then the method executes the transfer - * - */ - - public void removeAmount() { - String amount; - boolean askGood = false; - int finalAmount = 0; - System.out.println("Please enter the amount of the good you would like to REMOVE"); - Scanner keyboard = new Scanner(System.in); - //Prompts the user for the amount they would like to remove - amount = keyboard.nextLine(); - //The if statement checks that you have enough resources to make the transfer - try { - //The if statement checks that you have enough resources to make the transfer - if (Integer.parseInt(amount) <= player.getwOpium() || Integer.parseInt(amount) <= player.getwSilk() || Integer.parseInt(amount) <= player.getwGeneral() || Integer.parseInt(amount) <= player.getwArms()) { - finalAmount = Integer.parseInt(amount); - askGood = true; - } - //Else statement lets the user know that they do not hav enough goods to make the requested transfer - else { - System.out.println("Nice try but you don't have any items of that quantity in the warehouse!"); - askGood = false; - } - - //Ensures that goods are only transferred if they have the specified amount - //The user is prompted to enter which good they want to transfer - - if (askGood == true) { - String good; - System.out.println("Please enter a good to transfer O, S, G, A :"); - good = keyboard.nextLine(); - int held = 0; - //The following set of loops check to see which good the user has selected and makes the transfer and amount > 0 - if (Integer.parseInt(amount) > 0) { - if (good.equalsIgnoreCase("O")) { - if (player.getwOpium() >= Integer.parseInt(amount)) { - player.setwOpium(player.getwOpium() - Integer.parseInt(amount)); - held = player.getOpiumHeld(); - player.setOpiumHeld(held + finalAmount); - } else { - System.out.println("You don't have that much opium stored in the warehouse!"); - } - } else if (good.equalsIgnoreCase("S")) { - if (player.getwSilk() >= Integer.parseInt(amount)) { - player.setwSilk(player.getwSilk() - Integer.parseInt(amount)); - held = player.getSilkHeld(); - player.setSilkHeld(held + finalAmount); - } else { - System.out.println("You don't have that much silk stored in the warehouse!"); - } - } else if (good.equalsIgnoreCase("G")) { - if (player.getwGeneral() >= Integer.parseInt(amount)) { - player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount)); - held = player.getGeneralHeld(); - player.setGeneralHeld(held + finalAmount); - } else { - System.out.println("You don't have that much general cargo stored in the warehouse!"); - - } - } else if (good.equalsIgnoreCase("A")) { - if (player.getwArms() >= Integer.parseInt(amount)) { - player.setwArms(player.getwArms() - Integer.parseInt(amount)); - held = player.getArmsHeld(); - player.setArmsHeld(held + finalAmount); - } else { - System.out.println("You don't have that much arms stored in the warehouse!"); - - } - } - } - //Ensures the value entered is positive - else { - System.out.println("Sorry this transfer cannot be made"); - } - } - } - //If the program errors out this is the message displayed and the method is re-run, so that the game does not end. - catch (Exception e){ - System.out.println("Wait, that's not a valid input please try again"); - } - } - - /** - * This method prints the stock that is in the warehouse currently using the get and set - * methods from the player class. This is to allow the user to be able to know how much they have - * stored in the warehouse - */ - public void showWarehouse() { - System.out.println("--------------------\nWarehouse\n--------------------"); - System.out.println("Opium : " + player.getwOpium()); - System.out.println("Silk : " + player.getwSilk()); - System.out.println("General : " + player.getwGeneral()); - System.out.println("Arms : " + player.getwArms()); - } - - /** - * This method combines the add and remove methods and prompts the user to - * enter what they would like to do. Add or remove and accordingly invokes - * the required methods - */ - public void changeWarehouse() { - boolean keepGoing = true; - while (keepGoing) { - this.showWarehouse(); - String input = " "; - System.out.println("Would you like to add(A) or remove(R) resources? "); - Scanner keyboard = new Scanner(System.in); - input = keyboard.next(); - if (input.equalsIgnoreCase("R")) { - this.removeAmount(); - this.showWarehouse(); - } else if (input.equalsIgnoreCase("A")) { - this.addAmount(); - this.showWarehouse(); - - } - else{ - System.out.println("Don't waste the warehouse's time, try again later with a valid input"); - } - - String check; - //Check to see if the player wants to continue in the warehouse or they are done - System.out.println("Would you like to do any other business? Y / N?"); - check = keyboard.nextLine(); - check = keyboard.nextLine(); - - if (check.equalsIgnoreCase("Y")) { - keepGoing = true; - } else if (check.equalsIgnoreCase("N")) { - keepGoing = false; - } - } - } - + generalWarehouse.setText("General: " + player.getwGeneral()); + armsWarehouse.setText("Arms: " + player.getwArms()); + silkWarehouse.setText("Silk: " + player.getwSilk()); + opiumWarehouse.setText("Opium: " + player.getwOpium()); } - } diff --git a/src/loanShark.java b/src/loanShark.java deleted file mode 100644 index 828f17a..0000000 --- a/src/loanShark.java +++ /dev/null @@ -1,97 +0,0 @@ -import java.util.Scanner; - -public class loanShark { - private Player player; - /** - * setter method that takes in a Player object as an argument. - * - * @param player object of the class Player - */ - public void setPlayer(Player player) { - Player playerDummy = new Player(player); - this.player = playerDummy; - } - /** - * getter method for obtaining a player object. - * - * @return returns player object - */ - public Player getPlayer(){ - Player playerDummy = new Player(player); - return playerDummy; - } - /** - * Class Constructor that takes in a type player as a parameter - * - * @param player object of the class Player - */ - public loanShark(Player player){ - Player playerDummy = new Player(player); - this.player = playerDummy; - } - - /** - * This methods purpose is to loan the player the funds it wants - * or pay its outstanding debts. The method prompts the user if they - * would like to borrow money or repay. depending on what the player chooses - * the corresponding loop is evoked. The player can only be loaned 2 times the - * money they have minus the debt id their debt exceeds the cash balance, the loan - * cannot be given. - */ - public void loanMoney() { - boolean keepGoing = true; - while(keepGoing) { - String check; - Scanner keyboard = new Scanner(System.in); - System.out.println("Would you like to return money or borrow money?"); - //Prompts the user or what they would like to do - check = keyboard.nextLine(); - //If the user chooses to return money, the money is subtracted from the cash amount and debt - if(check.equalsIgnoreCase("r")){ - int returnAsk = 0; - System.out.println("Please enter how much you would like to return?"); - returnAsk = keyboard.nextInt(); - if(returnAsk <= player.getDebt() && returnAsk >= 0) { - player.setDebt(player.getDebt() - returnAsk); - player.setMoney(player.getMoney() - returnAsk); - } - //if you try to return more money than you owe it wont allow you to - else if(returnAsk > player.getDebt()){ - System.out.println("You don't need to return that much!"); - } - //No negative amounts are allowed - else{ - System.out.println("You can't return a negative amount."); - } - - } - //If the user chooses to borrow, the money is added to cash and the debt is increased - else if(check.equalsIgnoreCase("b")){ - int loanAsk = 0; - System.out.println("Please enter how much you would like to borrow"); - //Prompts user for the amount they would like to borrow - loanAsk = keyboard.nextInt(); - if(loanAsk <= 2*(player.getMoney() - player.getDebt())&& loanAsk >= 0) { - player.setDebt(player.getDebt() + loanAsk); - player.setMoney(player.getMoney() + loanAsk); - } - //If the requested money exceeds 2*(cash - debt) then the loan cannot be given - else{ - System.out.println("Sorry you can't be loaned that much"); - break; - } - } - //Asks the player if they have any other things to do with the load shark - System.out.println("Would you like to do any other business? Y / N?"); - check = keyboard.nextLine(); - check = keyboard.nextLine(); - - if(check.equalsIgnoreCase("Y")) { - keepGoing = true; - } - else if(check.equalsIgnoreCase("N")) { - keepGoing = false; - } - } - } -} diff --git a/src/main.java b/src/main.java deleted file mode 100644 index f763471..0000000 --- a/src/main.java +++ /dev/null @@ -1,55 +0,0 @@ -public class main { - - private Player player = new Player(); - - /** - * getter method for the Player object player. - * - * @return returns a copy of the object player - */ - - public Player getPlayer(){ - Player copy = new Player(player); - return copy; - } - - /** - * Initializes the Taipan shop with the players stats after the player finishes shopping, it updates the player object and returns it. - * - * @param shop player object from the main class used to update the shop class - */ - - public void shop(TaipanShop shop){ - shop.setPlayer(player); - shop.shop(); - player = shop.getPlayer(); - } - - /** - * Initializes the player object with 5 guns or $400 and $5000 debt. - * - * @param start player object from the main class used to update the start class - */ - - public void start(Start start){ - start.setPlayer(player); - start.initialize(); - player = start.getPlayer(); - } - - /** - * Updates main class with player data and starts the game. - * The game will only run as long as the player has not retired or has been destroyed. - * @param args Just the console for the player to look at. - */ - public static void main(String[] args) { - main main = new main(); - TaipanShop littyShop = new TaipanShop(main.getPlayer()); - Start start = new Start(main.getPlayer()); - - main.start(start); - while(!main.getPlayer().getRetire()){ - main.shop(littyShop); - } - } -}