From f3721c016edaa2e9a3e1c33a6b3b35c69ff3654e Mon Sep 17 00:00:00 2001 From: siddhantdewani <47336797+siddhantdewani@users.noreply.github.com> Date: Thu, 21 Feb 2019 20:18:11 -0700 Subject: [PATCH 1/7] Add files via upload --- src/Warehouse.java | 136 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 src/Warehouse.java 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(); + } +} From 5c5aff2ae0a69acd1a67c7dd1a9c03c1d17c63b1 Mon Sep 17 00:00:00 2001 From: siddhantdewani <47336797+siddhantdewani@users.noreply.github.com> Date: Thu, 21 Feb 2019 20:55:23 -0700 Subject: [PATCH 2/7] Update Player.java --- src/Player.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Player.java b/src/Player.java index a780855..8460447 100644 --- a/src/Player.java +++ b/src/Player.java @@ -10,8 +10,15 @@ public class Player { private int location = 1; private int guns = 3; private int HP = 100; + + public int getDebt() { + return debt; + } - + public void setDebt(int debt) { + this.debt = debt; + } + public String getName() { return name; } From 0a4968998c082d74bc477f0f1d797fc43c256b2a Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:07:08 -0700 Subject: [PATCH 3/7] Create main.java the main file --- src/main.java | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/main.java 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); + } +} From 2395eb32982932b54b907b88cba2a24322eef177 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:07:27 -0700 Subject: [PATCH 4/7] Update Player.java --- src/Player.java | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/Player.java b/src/Player.java index 8460447..2ec2b75 100644 --- a/src/Player.java +++ b/src/Player.java @@ -10,15 +10,23 @@ public class Player { private int location = 1; private int guns = 3; private int HP = 100; - - public int getDebt() { - return debt; - } - public void setDebt(int debt) { - this.debt = debt; - } - + 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; } @@ -122,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(); - } - } From 0a93de3354171d9e3df9fd1123bdceb8e9ef2d23 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:07:51 -0700 Subject: [PATCH 5/7] Update TaipanShop.java --- src/TaipanShop.java | 244 +++++++++++++++++++++++--------------------- 1 file changed, 128 insertions(+), 116 deletions(-) diff --git a/src/TaipanShop.java b/src/TaipanShop.java index ebd865d..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,70 +141,70 @@ 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")) { boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + getName() + "?"); + 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, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")"); + 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 <= getMoney() / opiumPrice && num >= 0) { - setOpiumHeld(getOpiumHeld()+num); - setMoney(getMoney()-num * opiumPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); + 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, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")"); + 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 <= getMoney() / silkPrice && num >= 0) { - setSilkHeld(getSilkHeld()+num); - setMoney(getMoney()-num * silkPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); + 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, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")"); + 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 <= getMoney() / armsPrice && num >= 0) { - setArmsHeld(getArmsHeld()+num); - setMoney(getMoney() - num*armsPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); + 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, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")"); + 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 <= getMoney() / generalPrice && num >= 0) { - setGeneralHeld(getGeneralHeld()+num); - setMoney(getMoney() - num*generalPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); + System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); } } } @@ -197,63 +213,63 @@ public class TaipanShop extends Player { } else if (response.equalsIgnoreCase("S")) { boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + getName() + "?"); + 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, " + getName() + "? (You have " + getOpiumHeld() + ")"); + System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getOpiumHeld() && num >= 0) { - setOpiumHeld(getOpiumHeld()-num); - setMoney(getMoney() + num*opiumPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); + 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, " + getName() + "? (You have " + getSilkHeld() + ")"); + System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getSilkHeld() && num >= 0) { - setSilkHeld(getSilkHeld()-num); - setMoney(getMoney() + num*silkPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); + 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, " + getName() + "? (You have " + getArmsHeld() + ")"); + System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getArmsHeld() && num >= 0) { - setArmsHeld(getArmsHeld()-num); - setMoney(getMoney() + num*armsPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); + 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, " + getName() + "? (You have " + getGeneralHeld() + ")"); + System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getGeneralHeld() && num >= 0) { - setGeneralHeld(getGeneralHeld()-num); - setMoney(getMoney() + num*generalPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); + System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); } } } @@ -276,63 +292,63 @@ public class TaipanShop extends Player { String response = input.next(); if (response.equalsIgnoreCase("B")) { boolean notDone2 = true; - System.out.println("What do you wish me to buy, " + getName() + "?"); + 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, " + getName() + "? (You can afford " + getMoney() / opiumPrice + ")"); + 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 <= getMoney() / opiumPrice && num >= 0) { - setOpiumHeld(getOpiumHeld()+num); - setMoney(getMoney() - num*opiumPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Opium?"); + 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, " + getName() + "? (You can afford " + getMoney() / silkPrice + ")"); + 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 <= getMoney() / silkPrice && num >= 0) { - setSilkHeld(getSilkHeld()+num); - setMoney(getMoney() - num*silkPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Silk?"); + 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, " + getName() + "? (You can afford " + getMoney() / armsPrice + ")"); + 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 <= getMoney() / armsPrice && num >= 0) { - setArmsHeld(getArmsHeld()+num); - setMoney(getMoney() - num*armsPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " Arms?"); + 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, " + getName() + "? (You can afford " + getMoney() / generalPrice + ")"); + 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 <= getMoney() / generalPrice && num >= 0) { - setGeneralHeld(getGeneralHeld()+num); - setMoney(getMoney() - num*generalPrice); + 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(getName() + ", you can't afford that!"); + System.out.println(player.getName() + ", you can't afford that!"); } else { - System.out.println(getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); + System.out.println(player.getName() + ", how am I supposed to buy " + "'" + num + "'" + " General Cargo?"); } } } @@ -341,63 +357,63 @@ public class TaipanShop extends Player { } else if (response.equalsIgnoreCase("S")) { boolean notDone2 = true; - System.out.println("What do you wish me to sell, " + getName() + "?"); + 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, " + getName() + "? (You have " + getOpiumHeld() + ")"); + System.out.println("\nHow much Opium shall I sell, " + player.getName() + "? (You have " + player.getOpiumHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getOpiumHeld() && num >= 0) { - setOpiumHeld(getOpiumHeld()-num); - setMoney(getMoney() + num*opiumPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Opium?"); + 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, " + getName() + "? (You have " + getSilkHeld() + ")"); + System.out.println("\nHow much Silk shall I sell, " + player.getName() + "? (You have " + player.getSilkHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getSilkHeld() && num >= 0) { - setSilkHeld(getSilkHeld()-num); - setMoney(getMoney() + num*silkPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Silk?"); + 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, " + getName() + "? (You have " + getArmsHeld() + ")"); + System.out.println("\nHow many Arms shall I sell, " + player.getName() + "? (You have " + player.getArmsHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getArmsHeld() && num >= 0) { - setArmsHeld(getArmsHeld()-num); - setMoney(getMoney() + num*armsPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " Arms?"); + 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, " + getName() + "? (You have " + getGeneralHeld() + ")"); + System.out.println("\nHow much General Cargo shall I sell, " + player.getName() + "? (You have " + player.getGeneralHeld() + ")"); while (notDone2) { int num = input.nextInt(); - if (num <= getGeneralHeld() && num >= 0) { - setGeneralHeld(getGeneralHeld()-num); - setMoney(getMoney() + num*generalPrice); + 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(getName() + ", you don't have that many to sell!"); + System.out.println(player.getName() + ", you don't have that many to sell!"); } else { - System.out.println(getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); + System.out.println(player.getName() + ", how am I supposed to sell " + "'" + num + "'" + " General Cargo?"); } } } @@ -410,8 +426,4 @@ public class TaipanShop extends Player { } } - public static void main(String[] args){ - TaipanShop shop = new TaipanShop(); - shop.shop(); - } -} \ No newline at end of file +} From 154032398536f49ce197f45e1012d5860ead9d48 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:08:11 -0700 Subject: [PATCH 6/7] Update ShipWarfare.java --- src/ShipWarfare.java | 57 ++++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java index 4936949..b30e333 100644 --- a/src/ShipWarfare.java +++ b/src/ShipWarfare.java @@ -2,16 +2,32 @@ import java.util.Scanner; import java.util.Random; import java.util.concurrent.TimeUnit; -public class ShipWarfare extends Player { +public class ShipWarfare{ private int numOfPeasantShips = 0; private boolean userAttacks = true; + private Player player; + public ShipWarfare(Player player){ + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public void setPlayer(Player player) { + Player playerDummy = new Player(player); + this.player = playerDummy; + } + + public Player getPlayer(){ + Player playerDummy = new Player(player); + return playerDummy; + } 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 ships\nCurrently our ship status is %d%%\n", getMoney(), getNumOfPeasantShips(),getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfPeasantShips(),player.getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfPeasantShips(),player.getHP()); fightOrRunMessage(); while (true) { String response = userResponse.nextLine(); @@ -43,7 +59,8 @@ public class ShipWarfare extends Player { public void fightOrRunMessage() { - System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", getGuns()); + System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns()); + System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns()); } @@ -65,16 +82,16 @@ public class ShipWarfare extends Player { int numOfShipsAttacking = 0; Random randomValue = new Random(); - if (getMoney() <= 100000) { + if (player.getMoney() <= 100000) { //Minimum one ship will attack, maximum 20 numOfShipsAttacking = randomValue.nextInt(20) + 1; - } else if (getMoney() <= 200000) { + } else if (player.getMoney() <= 200000) { //Minimum 30 Ships will attack, maximum 70 numOfShipsAttacking = randomValue.nextInt(40) + 30; - } else if (getMoney() <= 500000) { + } else if (player.getMoney() <= 500000) { //Minimum 50 ships will attack, maximum 140 numOfShipsAttacking = randomValue.nextInt(90) + 50; - } else if (getMoney() > 1000000) { + } else if (player.getMoney() > 1000000) { //Minimum 100 ships will attack, maximum 300 ships numOfShipsAttacking = randomValue.nextInt(3) + 100; } @@ -103,7 +120,7 @@ public class ShipWarfare extends Player { //Player volley while (exitValue == 0) { - for (int j = 0; j < getGuns(); j++) { + for (int j = 0; j < player.getGuns(); j++) { if (userAttacks == true) { int hitOrMiss = randomValue.nextInt(2) + 1; if (hitOrMiss == 2) { @@ -136,23 +153,23 @@ public class ShipWarfare extends Player { delayForASecond(); //Computer volley int takeGunChance = randomValue.nextInt(4) + 1; - if (takeGunChance == 1 && getGuns() > 0) { - setGuns(getGuns() - 1); + if (takeGunChance == 1 && player.getGuns() > 0) { + player.setGuns(player.getGuns() - 1); System.out.println("Dang it! They destroyed one of our guns"); } else { - setHP(getHP() - (1 + randomValue.nextInt(10))); + player.setHP(player.getHP() - (1 + randomValue.nextInt(10))); } - if (getHP() <= 0) { + if (player.getHP() <= 0) { exitValue = 2; break; } - System.out.printf("EEK, our current ship status is %d%% \n", getHP()); + System.out.printf("EEK, our current ship status is %d%% \n", player.getHP()); delayForASecond(); 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)", getGuns()); + System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)", player.getGuns()); String response = userInput.nextLine(); if (response.equalsIgnoreCase("r")) { @@ -169,13 +186,13 @@ public class ShipWarfare extends Player { 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", getHP()); + 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()); return true; } else if (exitValue == 2) { - gameOver(); + player.gameOver(); return true; } else if (exitValue == 3) { - System.out.printf("We made it out at %d%% ship status!\n", getHP()); + System.out.printf("We made it out at %d%% ship status!\n", player.getHP()); return true; } return false; @@ -185,10 +202,4 @@ public class ShipWarfare extends Player { //Type of ship implied to be Liu Yen fleet - public static void main(String[] args) throws Exception { - ShipWarfare littyObject = new ShipWarfare(); - littyObject.peasantFleetAttack(); - } - } - From b78ba180f540fb56bfd9bdb49fc48bff95fe2737 Mon Sep 17 00:00:00 2001 From: Vikramb987 <47336882+Vikramb987@users.noreply.github.com> Date: Thu, 21 Feb 2019 22:08:26 -0700 Subject: [PATCH 7/7] Update Travel.java --- src/Travel.java | 76 ++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 33 deletions(-) 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(); - } }