diff --git a/src/Player.java b/src/Player.java index d1deca3..ee0c02b 100644 --- a/src/Player.java +++ b/src/Player.java @@ -11,6 +11,10 @@ public class Player { private int guns = 0; private int HP = 100; private int debt = 0; + private int wOpium = 0; + private int wSilk = 0; + private int wGeneral = 0; + private int wArms = 0; private boolean retire = false; public Player(){ @@ -28,6 +32,11 @@ public class Player { this.guns = player.guns; this.HP = player.HP; this.debt = player.debt; + this.wOpium = player.wOpium; + this.wSilk = player.wSilk; + this.wGeneral = player.wGeneral; + this.wArms = player.wArms; + } public boolean getRetire(){ @@ -148,6 +157,38 @@ public class Player { } } + public int getwOpium(){ return wOpium; } + + public void setwOpium(int wOpium) { + if (wOpium >= 0){ + this.wOpium = wOpium; + } + } + + public int getwSilk(){return wSilk;} + + public void setwSilk(int wSilk) { + if (wSilk >= 0){ + this.wSilk = wSilk; + } + } + + public int getwGeneral(){return wGeneral;} + + public void setwGeneral(int wGeneral) { + if (wGeneral >= 0){ + this.wGeneral = wGeneral; + } + } + + public int getwArms(){return wArms;} + + public void setwArms(int wArms) { + if (wArms >= 0){ + this.wArms = wArms; + } + } + public void gameOver(){ System.out.flush(); System.out.println("Game over"); diff --git a/src/Warehouse.java b/src/Warehouse.java index 538f418..d2ea689 100644 --- a/src/Warehouse.java +++ b/src/Warehouse.java @@ -1,10 +1,10 @@ import java.util.Scanner; public class Warehouse { - private int wOpium = 0; + /*private int wOpium = 0; private int wSilk = 0; private int wGeneral = 0; - private int wArms = 0; + private int wArms = 0;*/ private Player player; @@ -47,7 +47,7 @@ public class Warehouse { if (Integer.parseInt(amount) > 0) { if (good.equalsIgnoreCase("O")) { if (player.getOpiumHeld() >= Integer.parseInt(amount)) { - this.wOpium += finalAmount; + player.setwOpium(player.getwOpium() + finalAmount); held = player.getOpiumHeld(); player.setOpiumHeld(held - finalAmount); System.out.println(player.getOpiumHeld()); @@ -56,7 +56,7 @@ public class Warehouse { } } else if (good.equalsIgnoreCase("S")) { if (player.getSilkHeld() >= Integer.parseInt(amount)) { - this.wSilk += finalAmount; + player.setwSilk(player.getwSilk() + finalAmount); held = player.getSilkHeld(); player.setSilkHeld(held - finalAmount); } else { @@ -65,7 +65,7 @@ public class Warehouse { } } else if (good.equalsIgnoreCase("G")) { if (player.getGeneralHeld() >= Integer.parseInt(amount)) { - this.wGeneral += finalAmount; + player.setwGeneral(player.getwGeneral() + finalAmount); held = player.getGeneralHeld(); player.setGeneralHeld(held - finalAmount); } else { @@ -74,7 +74,7 @@ public class Warehouse { } } else if (good.equalsIgnoreCase("A")) { if (player.getArmsHeld() >= Integer.parseInt(amount)) { - this.wArms += finalAmount; + player.setwArms(player.getwArms() + finalAmount); held = player.getArmsHeld(); player.setArmsHeld(held - finalAmount); } else { @@ -98,7 +98,7 @@ public class Warehouse { Scanner keyboard = new Scanner(System.in); amount = keyboard.nextLine(); try { - if (Integer.parseInt(amount) <= wOpium || Integer.parseInt(amount) <= wSilk || Integer.parseInt(amount) <= wGeneral || Integer.parseInt(amount) <= wArms) { + 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 { @@ -113,24 +113,24 @@ public class Warehouse { int held = 0; if (Integer.parseInt(amount) > 0) { if (good.equalsIgnoreCase("O")) { - if (this.wOpium >= Integer.parseInt(amount)) { - this.wOpium -= Integer.parseInt(amount); + 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 (this.wSilk >= Integer.parseInt(amount)) { - this.wSilk -= Integer.parseInt(amount); + 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 (this.wGeneral >= Integer.parseInt(amount)) { - this.wGeneral -= Integer.parseInt(amount); + if (player.getwGeneral() >= Integer.parseInt(amount)) { + player.setwGeneral(player.getwGeneral() - Integer.parseInt(amount)); held = player.getGeneralHeld(); player.setGeneralHeld(held + finalAmount); } else { @@ -138,8 +138,8 @@ public class Warehouse { } } else if (good.equalsIgnoreCase("A")) { - if (this.wArms >= Integer.parseInt(amount)) { - this.wArms -= Integer.parseInt(amount); + if (player.getwArms() >= Integer.parseInt(amount)) { + player.setwArms(player.getwArms() - Integer.parseInt(amount)); held = player.getArmsHeld(); player.setArmsHeld(held + finalAmount); } else { @@ -159,10 +159,10 @@ public class Warehouse { public void showWarehouse() { System.out.println("--------------------\nWarehouse\n--------------------"); - System.out.println("Opium : " + this.wOpium); - System.out.println("Silk : " + this.wSilk); - System.out.println("General : " + this.wGeneral); - System.out.println("Arms : " + this.wArms); + System.out.println("Opium : " + player.getwOpium()); + System.out.println("Silk : " + player.getwSilk()); + System.out.println("General : " + player.getwGeneral()); + System.out.println("Arms : " + player.getwArms()); } @@ -185,7 +185,7 @@ public class Warehouse { String check; System.out.println("Would you like to do any other business? Y / N?"); check = keyboard.nextLine(); - check = keyboard.nextLine(); + check = keyboard.nextLine(); if (check.equalsIgnoreCase("Y")) { keepGoing = true;