diff --git a/src/Player.java b/src/Player.java index 73cbed6..1544158 100644 --- a/src/Player.java +++ b/src/Player.java @@ -11,6 +11,21 @@ public class Player { private int guns = 3; private int HP = 100; + public Player(){ + + } + + public Player(Player player){ + this.bank = player.bank; + this.money = player.money; + this.opiumHeld = player.opiumHeld; + this.silkHeld = player.silkHeld; + this.generalHeld = player.generalHeld; + this.armsHeld = player.armsHeld; + this.location = player.location; + this.guns = player.guns; + this.HP = player.HP; + } public String getName() { return name; @@ -115,15 +130,4 @@ public class Player { System.out.println("Game over"); } - public static void main(String[] args) throws Exception { - ShipWarfare littyWarfare = new ShipWarfare(); - TaipanShop littyShop = new TaipanShop(); - - littyShop.shop(); - - littyWarfare.peasantFleetAttack(); - - littyShop.shop(); - } - } diff --git a/src/TaipanShop.java b/src/TaipanShop.java index 97205a3..b02cb72 100644 --- a/src/TaipanShop.java +++ b/src/TaipanShop.java @@ -1,7 +1,8 @@ import java.util.Random; import java.util.Scanner; -public class TaipanShop extends Player { - +public class TaipanShop { + + private Player player; private int cargoSpace = 60; private int currentCargo = 0; private int opiumPrice = 16000; @@ -9,6 +10,21 @@ public class TaipanShop extends Player { private int armsPrice = 160; private int generalPrice = 8; + public void setPlayer(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public Player getPlayer(){ + Player playerDummy = new Player(player); + return playerDummy; + } + + public TaipanShop(Player player){ + Player playerDummy = new Player(player); + this.player = playerDummy; + } + public int getCargoSpace() { return cargoSpace; } @@ -60,7 +76,7 @@ public class TaipanShop extends Player { } private void updatePrices(){ - String s = "\n" + getName() + ", the price of "; + String s = "\n" + player.getName() + ", the price of "; double value = 80*Math.random(); Random rand = new Random(); opiumPrice = (rand.nextInt(201) + 60)*100; @@ -105,18 +121,18 @@ public class TaipanShop extends Player { } private void printShop(){ - currentCargo = getOpiumHeld()+getGuns()*10+getSilkHeld()+getArmsHeld()+getGeneralHeld(); + currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld(); if(cargoSpace - currentCargo < 0){ - System.out.println("Hold: Overloaded" + " Guns: " + getGuns()); + System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns()); }else{ - System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + getGuns()); + System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns()); } System.out.println("-------------------------------------------------------------"); - System.out.println(" Opium: " + getOpiumHeld() + " Silk: " + getSilkHeld()); - System.out.println(" Arms: " + getArmsHeld() + " General: " + getGeneralHeld()); + 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: " + getMoney() + " Bank: " + getBank()+"\n"); - System.out.println(getName() + ", present prices per unit here are:"); + System.out.println("Cash: " + player.getMoney() + " Bank: " + player.getBank()+"\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); } @@ -125,16 +141,140 @@ public class TaipanShop extends Player { updatePrices(); Scanner input = new Scanner(System.in); boolean notDone = true; - if (getLocation() == 1) { + if (player.getLocation() == 1) { while (notDone) { printShop(); System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?"); String response = input.next(); if (response.equalsIgnoreCase("B")) { - ayyy(input); + boolean notDone2 = true; + System.out.println("What do you wish me to buy, " + player.getName() + "?"); + 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?"); + } + } + } + + } } else if (response.equalsIgnoreCase("S")) { - duplicateLittiness(input); + 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")) { System.out.println("\n*** PLACEHOLDER FOR BANK ***\n"); @@ -151,10 +291,133 @@ public class TaipanShop extends Player { System.out.println("\nShall I Buy, Sell, or Quit Trading?"); String response = input.next(); if (response.equalsIgnoreCase("B")) { - ayyy(input); + boolean notDone2 = true; + System.out.println("What do you wish me to buy, " + player.getName() + "?"); + 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?"); + } + } + } + + } } else if (response.equalsIgnoreCase("S")) { - duplicateLittiness(input); + 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("Q")) { System.out.println("\n*** PLACEHOLDER FOR TRAVEL ***\n"); notDone = false; @@ -163,143 +426,4 @@ public class TaipanShop extends Player { } } - - public void duplicateLittiness(Scanner input) { - String response; - boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + getName() + "?"); - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I sell, " + getName() + "? (You have " + getOpiumHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getOpiumHeld() && num >= 0) { - setOpiumHeld(getOpiumHeld()-num); - setMoney(getMoney() + num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you don't have that many to sell!"); - } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I sell, " + getName() + "? (You have " + getSilkHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getSilkHeld() && num >= 0) { - setSilkHeld(getSilkHeld()-num); - setMoney(getMoney() + num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you don't have that many to sell!"); - } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I sell, " + getName() + "? (You have " + getArmsHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getArmsHeld() && num >= 0) { - setArmsHeld(getArmsHeld()-num); - setMoney(getMoney() + num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you don't have that many to sell!"); - } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I sell, " + getName() + "? (You have " + getGeneralHeld() + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getGeneralHeld() && num >= 0) { - setGeneralHeld(getGeneralHeld()-num); - setMoney(getMoney() + num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you don't have that many to sell!"); - } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - } - - public void ayyy(Scanner input) { - String response; - boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + getName() + "?"); - while (notDone2) { - response = input.nextLine(); - if (response.equalsIgnoreCase("O")) { - System.out.println("\nHow much Opium shall I buy, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getMoney() / opiumPrice && num >= 0) { - setOpiumHeld(getOpiumHeld()+num); - setMoney(getMoney() - num*opiumPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you can't afford that!"); - } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); - } - } - } else if (response.equalsIgnoreCase("S")) { - System.out.println("\nHow much Silk shall I buy, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getMoney() / silkPrice && num >= 0) { - setSilkHeld(getSilkHeld()+num); - setMoney(getMoney() - num*silkPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you can't afford that!"); - } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); - } - } - } else if (response.equalsIgnoreCase("A")) { - System.out.println("\nHow many Arms shall I buy, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getMoney() / armsPrice && num >= 0) { - setArmsHeld(getArmsHeld()+num); - setMoney(getMoney() - num*armsPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you can't afford that!"); - } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); - } - } - } else if (response.equalsIgnoreCase("G")) { - System.out.println("\nHow much General Cargo shall I buy, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")"); - while (notDone2) { - int num = input.nextInt(); - if (num <= getMoney() / generalPrice && num >= 0) { - setGeneralHeld(getGeneralHeld()+num); - setMoney(getMoney() - num*generalPrice); - notDone2 = false; - } else if (num >= 0) { - System.out.println(getName() + ", you can't afford that!"); - } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); - } - } - } - - } - } - - public static void main(String[] args){ - TaipanShop shop = new TaipanShop(); - shop.shop(); - } -} \ No newline at end of file +} diff --git a/src/Travel.java b/src/Travel.java index 039385d..62a1dbd 100644 --- a/src/Travel.java +++ b/src/Travel.java @@ -1,64 +1,79 @@ import java.util.Random; import java.util.Scanner; -public class Travel extends Player { +public class Travel { - private void seaAtlas(int locationOfTravel){ + private Player player; + + public void Player(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public Player getPlayer() { + Player playerDummy = new Player(player); + return playerDummy; + } + + public Travel(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + private void seaAtlas(int locationOfTravel) { switch (locationOfTravel) { case 1: System.out.println("\nArriving at Hong Kong"); - setLocation(1); + player.setLocation(1); break; case 2: System.out.println("\nArriving at Shanghai"); - setLocation(2); + player.setLocation(2); break; case 3: System.out.println("\nArriving at Nagasaki"); - setLocation(3); + player.setLocation(3); break; case 4: System.out.println("\nArriving at Saigon"); - setLocation(4); + player.setLocation(4); break; case 5: System.out.println("\nArriving at Manila"); - setLocation(5); + player.setLocation(5); break; case 6: System.out.println("\nArriving at Singapore"); - setLocation(6); + player.setLocation(6); break; case 7: System.out.println("\nArriving at Batavia"); - setLocation(7); + player.setLocation(7); break; } } private void randomEventSea(int locationOfTravel) throws Exception { - ShipWarfare attackShip = new ShipWarfare(); + ShipWarfare attackShip = new ShipWarfare(player); Random rand = new Random(); int randGenNum = rand.nextInt(3) + 1; - if(randGenNum == 1){ + if (randGenNum == 1) { attackShip.peasantFleetAttack(); - } - else if(randGenNum == 2){ + } else if (randGenNum == 2) { disaster(locationOfTravel); } System.out.println("We made it!"); } - private void disaster(int locationOfTravel){ - System.out.print("Storm "+getName()+"! "); + private void disaster(int locationOfTravel) { + System.out.print("Storm " + player.getName() + "! "); Random rand = new Random(); int randGenNum = rand.nextInt(5) + 1; - if(randGenNum <= 2){ + if (randGenNum <= 2) { System.out.println(" We made it through!"); - } - else{ - while(randGenNum == locationOfTravel){ + } else { + while (randGenNum == locationOfTravel) { randGenNum = rand.nextInt(7) + 1; if (randGenNum != locationOfTravel) { System.out.println("We've been blown off course!"); @@ -68,36 +83,31 @@ public class Travel extends Player { } } - public void travelTo(){ + public void travelTo() { Scanner keyboard = new Scanner(System.in); String response; int tempInt; boolean hasTraveled = false; while (true) { - System.out.println("\n" + getName() + ", do you wish to go to:\n"); + 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(); try { tempInt = Integer.parseInt(response); - System.out.println(tempInt + " " + getLocation()); - if(tempInt != getLocation()){ + System.out.println(tempInt + " " + player.getLocation()); + if (tempInt != player.getLocation()) { randomEventSea(tempInt); seaAtlas(tempInt); hasTraveled = true; - } - else System.out.println("\nYou're already here " + getName() + "."); + } else System.out.println("\nYou're already here " + player.getName() + "."); + } catch (Exception e) { + System.out.print("\nSorry, " + player.getName() + " could you say that again?"); } - catch (Exception e){ - System.out.print("\nSorry, " + getName() + " could you say that again?"); + if (hasTraveled) { + break; } - if(hasTraveled){break;} } } - - public static void main(String[] args){ - Travel ship = new Travel(); - ship.travelTo(); - } } diff --git a/src/Warehouse.java b/src/Warehouse.java new file mode 100644 index 0000000..0c284a0 --- /dev/null +++ b/src/Warehouse.java @@ -0,0 +1,136 @@ +import java.util.Scanner; + +public class Warehouse extends Player { + private int wOpium = 25; + private int wSilk = 0; + private int wGeneral = 0; + private int wArms = 0; + private String good = ""; + private int finalAmount = 0; + + public void addAmount(String good, int amount) { + int held = 0; + if (amount > 0) { + if (this.good.equalsIgnoreCase("O")) { + this.wOpium += amount; + held = getOpiumHeld(); + setOpiumHeld(held - amount); + System.out.println(getOpiumHeld()); + } + else if(this.good.equalsIgnoreCase("S")) { + this.wSilk += amount; + held = getSilkHeld(); + setSilkHeld(held - amount); + } + else if(this.good.equalsIgnoreCase("G")) { + this.wGeneral += amount; + held = getGeneralHeld(); + setGeneralHeld(held - amount); + } + else if(this.good.equalsIgnoreCase("A")) { + this.wArms += amount; + held = getArmsHeld(); + setArmsHeld(held - amount); + } + } + else { + System.out.println("Sorry this transfer cannot be made"); + } + } + public void removeAmount(String good, int amount) { + int held = 0; + if (amount > 0) { + if (this.good.equalsIgnoreCase("O")) { + this.wOpium -= amount; + held = getOpiumHeld(); + setOpiumHeld(held + amount); + } + else if(this.good.equalsIgnoreCase("S")) { + this.wSilk -= amount; + held = getSilkHeld(); + setSilkHeld(held + amount); + } + else if(this.good.equalsIgnoreCase("G")) { + this.wGeneral -= amount; + held = getGeneralHeld(); + setGeneralHeld(held + amount); + } + else if(this.good.equalsIgnoreCase("A")) { + this.wArms -= amount; + held = getArmsHeld(); + setArmsHeld(held + amount); + } + } + else { + System.out.println("Sorry this transfer cannot be made"); + } + + } + + public void showWarehouse() { + System.out.println("Opium : " + this.wOpium); + System.out.println("Silk : " + this.wSilk); + System.out.println("General : " + this.wGeneral); + System.out.println("Arms : " + this.wArms); + } + + private void askGood() { + String aGood = "k"; + System.out.println("Please enter a good to transfer O, S, G, A :"); + Scanner keyboard = new Scanner(System.in); + aGood = keyboard.nextLine(); + aGood = aGood.toUpperCase(); + this.good = aGood; + } + + public void askAddAmount() { + askGood(); + int amount = 0; + System.out.println("Please enter the amount of the good you would like to transfer, put negative amount to remove"); + Scanner keyboard = new Scanner(System.in); + amount = keyboard.nextInt(); + if(this.good.equalsIgnoreCase("O") && amount <= getOpiumHeld()) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("S") && amount <= getSilkHeld()) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("G") && amount <= getGeneralHeld()) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("A") && amount <= getArmsHeld()) { + finalAmount = amount; + } + } + + public void askRemoveAmount() { + askGood(); + int amount = 0; + System.out.println("Please enter the amount of the good you would like to remove"); + Scanner keyboard = new Scanner(System.in); + amount = keyboard.nextInt(); + if(this.good.equalsIgnoreCase("O") && amount <= this.wOpium) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("S") && amount <= this.wSilk) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("G") && amount <= this.wGeneral) { + finalAmount = amount; + } + else if(this.good.equalsIgnoreCase("A") && amount <= this.wArms) { + finalAmount = amount; + } + + } + public static void main(String[] args){ + Warehouse hi = new Warehouse(); + hi.showWarehouse(); + hi.askRemoveAmount(); + hi.removeAmount(hi.good, hi.finalAmount); + hi.showWarehouse(); + hi.askAddAmount(); + hi.addAmount(hi.good, hi.finalAmount); + hi.showWarehouse(); + } +} diff --git a/src/main.java b/src/main.java new file mode 100644 index 0000000..eab0969 --- /dev/null +++ b/src/main.java @@ -0,0 +1,28 @@ +public class main { + + private static Player player = new Player(); + + public void shop(TaipanShop shop){ + shop.setPlayer(player); + shop.shop(); + player = shop.getPlayer(); + } + + public void peasantFleet(ShipWarfare warfare) throws Exception { + warfare.setPlayer(player); + warfare.peasantFleetAttack(); + player = warfare.getPlayer(); + } + + public static void main(String[] args) throws Exception { + main main = new main(); + ShipWarfare littyWarfare = new ShipWarfare(player); + TaipanShop littyShop = new TaipanShop(player); + + main.shop(littyShop); + + main.peasantFleet(littyWarfare); + + main.shop(littyShop); + } +}