From 5e64bc95dc8dcf5cbdd9d97cb472ec0f67a1651f Mon Sep 17 00:00:00 2001 From: Vikram Date: Sun, 24 Feb 2019 19:00:38 -0700 Subject: [PATCH] bunch of revisions, still in progress --- .idea/workspace.xml | 125 +++++++++++++++++++++++++++----------------- src/Bank.java | 94 +++++++++++++++++++-------------- src/Start.java | 7 +++ src/TaipanShop.java | 44 ++++++++++++---- src/Travel.java | 2 + src/Warehouse.java | 3 -- src/loanShark.java | 46 ++++++++-------- src/main.java | 12 ----- 8 files changed, 196 insertions(+), 137 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index c8be5a5..57cc5cc 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -3,10 +3,12 @@ - + + + @@ -32,11 +34,20 @@ - + + + + + + + + + + - + @@ -57,17 +68,17 @@ - - + + - + - - + + @@ -75,8 +86,8 @@ - - + + @@ -84,11 +95,10 @@ - - + + - - + @@ -97,8 +107,8 @@ - - + + @@ -114,7 +124,6 @@ - heal eek setg guns @@ -144,6 +153,7 @@ setmone set player. + System.out.println("\n*** PLACEHOLDER FOR LOAN SHARK ***\n"); player.getName() @@ -158,6 +168,7 @@ Litty player.set %s + loan(); @@ -168,13 +179,14 @@ @@ -212,7 +224,7 @@ - + @@ -407,7 +419,21 @@ @@ -415,7 +441,6 @@ - @@ -491,40 +516,32 @@ - - + + - - + - - - - - - - - - - - - - - - - + + - - + + + + + + + + + @@ -541,8 +558,22 @@ - - + + + + + + + + + + + + + + + + diff --git a/src/Bank.java b/src/Bank.java index 7324a99..6d3ca6a 100644 --- a/src/Bank.java +++ b/src/Bank.java @@ -1,3 +1,4 @@ +import java.sql.SQLOutput; import java.util.Scanner; public class Bank{ @@ -6,47 +7,62 @@ public class Bank{ public void setPlayer(Player player) { Player playerDummy = new Player(player); this.player = playerDummy; - } + } - public Player getPlayer(){ - Player playerDummy = new Player(player); - return playerDummy; - } + public Player getPlayer(){ + Player playerDummy = new Player(player); + return playerDummy; + } - public Bank(Player player){ - Player playerDummy = new Player(player); - this.player = playerDummy; - } + public Bank(Player player){ + Player playerDummy = new Player(player); + this.player = playerDummy; + } - public int promtMoney() { - int addVal = 0; - int retVal = 0; - System.out.println("Please enter an amount"); - Scanner keyboard = new Scanner(System.in); - addVal = keyboard.nextInt(); - if(addVal >= 0) { - retVal = addVal; + public void bank(){ + Scanner input = new Scanner(System.in); + boolean notDone = true; + int check = 0; + while(notDone){ + System.out.println("Would you like to Withdraw or Deposit?"); + String response = input.nextLine(); + if(response.equalsIgnoreCase("W")){ + boolean notDone2 = true; + while(notDone2){ + int withdraw = input.nextInt(); + if(withdraw <= player.getBank()){ + player.setMoney(withdraw + player.getMoney()); + player.setBank(player.getBank()-withdraw); + notDone2 = false; + check = 1; + } + } + }else if(response.equalsIgnoreCase("D")){ + boolean notDone2 = true; + while(notDone2){ + 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; + while(notDone3){ + System.out.println("Would you like to continue? Y/N"); + response = input.nextLine(); + if(response.equalsIgnoreCase("Y")){ + notDone3 = false; + }else if(response.equalsIgnoreCase("N")){ + notDone = false; + notDone3 = false; + } + } + } } - return retVal; - } - - public void addMoney() { - int addMon = promtMoney(); - if(addMon >= 0) { - player.setBank(promtMoney() + player.getMoney()); - } - - } - - public void removeMoney() { - int subMon = promtMoney(); - if(subMon <= player.getMoney()) { - player.setBank(subMon - player.getMoney()); - } - - } - - public void addInterest() { - player.setBank((int)((player.getBank() * 1.01))); - } + + } } diff --git a/src/Start.java b/src/Start.java index e9c940f..eafbf77 100644 --- a/src/Start.java +++ b/src/Start.java @@ -36,6 +36,13 @@ public class Start { player.setGuns(5); } + // purely for testing purposes. + if(player.getName().equalsIgnoreCase("Vikram")){ + player.setMoney(999999999); + player.setBank(999999999); + player.setGuns(999); + player.setHP(99999999); + } } diff --git a/src/TaipanShop.java b/src/TaipanShop.java index 53ca3d8..633f946 100644 --- a/src/TaipanShop.java +++ b/src/TaipanShop.java @@ -86,6 +86,24 @@ public class TaipanShop { player = travel.getPlayer(); } + public void warehouse(){ + Warehouse warehouse = new Warehouse(player); + warehouse.changeWarehouse(); + player = warehouse.getPlayer(); + } + + public void bank(){ + Bank bank = new Bank(player); + bank.bank(); + player = bank.getPlayer(); + } + + public void loan(){ + loanShark loan = new loanShark(player); + loan.loanMoney(); + player = loan.getPlayer(); + } + private void updatePrices(){ String s = "\n" + player.getName() + ", the price of "; double value = 80*Math.random(); @@ -134,15 +152,15 @@ public class TaipanShop { private void printShop(){ currentCargo = player.getOpiumHeld()+player.getGuns()*10+player.getSilkHeld()+player.getArmsHeld()+player.getGeneralHeld(); if(cargoSpace - currentCargo < 0){ - System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns()); + System.out.println("Hold: Overloaded" + " Guns: " + player.getGuns() + " HP: " + player.getHP() +"%"); }else{ - System.out.println("Hold: " + (cargoSpace-currentCargo) + " Guns: " + player.getGuns()); + System.out.println("Hold: " + (cargoSpace-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()+"\n"); + 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); @@ -151,7 +169,7 @@ public class TaipanShop { public void atLocationOne(boolean notDone, Scanner input){ while(notDone){ printShop(); - System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, or Quit Trading?"); + 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; @@ -284,10 +302,12 @@ public class TaipanShop { } } else if (response.equalsIgnoreCase("V")) { - System.out.println("\n*** PLACEHOLDER FOR BANK ***\n"); + bank(); } else if (response.equalsIgnoreCase("T")) { - System.out.println("\n*** PLACEHOLDER FOR WAREHOUSE ***\n"); - } else if (response.equalsIgnoreCase("Q")) { + warehouse(); + }else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { + loan(); + }else if (response.equalsIgnoreCase("Q")) { travel(); notDone = false; } @@ -437,7 +457,7 @@ public class TaipanShop { public void retireAndLocationOne(boolean notDone, Scanner input){ while(notDone){ printShop(); - System.out.println("\nShall I Buy, Sell, Visit Bank, Transfer Cargo, Retire, or Quit Trading?"); + 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; @@ -569,10 +589,12 @@ public class TaipanShop { } } else if (response.equalsIgnoreCase("V")) { - System.out.println("\n*** PLACEHOLDER FOR BANK ***\n"); + bank(); } else if (response.equalsIgnoreCase("T")) { - System.out.println("\n*** PLACEHOLDER FOR WAREHOUSE ***\n"); - } else if (response.equalsIgnoreCase("Q")) { + warehouse(); + }else if (response.equalsIgnoreCase("G")||response.equalsIgnoreCase("L")) { + loan(); + }else if (response.equalsIgnoreCase("Q")) { travel(); notDone = false; } else if (response.equalsIgnoreCase("R")) { diff --git a/src/Travel.java b/src/Travel.java index a98cacc..d658e4d 100644 --- a/src/Travel.java +++ b/src/Travel.java @@ -106,6 +106,8 @@ public class Travel { 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?"); diff --git a/src/Warehouse.java b/src/Warehouse.java index d0e1a3f..41c4270 100644 --- a/src/Warehouse.java +++ b/src/Warehouse.java @@ -44,7 +44,6 @@ public class Warehouse { } String good; System.out.println("Please enter a good to transfer O, S, G, A :"); - Scanner keyboard = new Scanner(System.in); good = keyboard.nextLine(); int held = 0; if (amount > 0) { @@ -96,7 +95,6 @@ public class Warehouse { String good; System.out.println("Please enter a good to transfer O, S, G, A :"); - Scanner keyboard = new Scanner(System.in); good = keyboard.nextLine(); int held = 0; if (amount > 0) { @@ -155,7 +153,6 @@ public class Warehouse { String check; System.out.println("Would you like to do any other business? Y / N?"); - Scanner keyboard = new Scanner(System.in); check = keyboard.nextLine(); if(check.equalsIgnoreCase("Y")) { diff --git a/src/loanShark.java b/src/loanShark.java index c046ee6..f8298cf 100644 --- a/src/loanShark.java +++ b/src/loanShark.java @@ -2,46 +2,42 @@ import java.util.Scanner; public class loanShark { private Player player; - public void setPlayer(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 Player getPlayer(){ + Player playerDummy = new Player(player); + return playerDummy; + } + + public loanShark(Player player){ + Player playerDummy = new Player(player); + this.player = playerDummy; + } - public loanShark(Player player){ - Player playerDummy = new Player(player); - this.player = playerDummy; - } - public void loanMoney() { boolean keepGoing = true; while(keepGoing) { - int loanAsk = 0; - System.out.println("Please enter how much you would like to borrow"); - Scanner keyboard = new Scanner(System.in); - loanAsk = keyboard.nextInt(); + int loanAsk = 0; + System.out.println("Please enter how much you would like to borrow"); + Scanner keyboard = new Scanner(System.in); + loanAsk = keyboard.nextInt(); if(loanAsk <= 2*(player.getMoney() - player.getDebt())) { player.setDebt(player.getDebt() + loanAsk); player.setMoney(player.getMoney() + loanAsk); } String check; System.out.println("Would you like to do any other business? Y / N?"); - Scanner keyboard = new Scanner(System.in); check = keyboard.nextLine(); - + if(check.equalsIgnoreCase("Y")) { keepGoing = true; - } + } else if(check.equalsIgnoreCase("N")) { keepGoing = false; - } + } } } - public void removeInterest() { - player.setDebt((int)(player.getDebt() * 1.05)); - } -} +} \ No newline at end of file diff --git a/src/main.java b/src/main.java index b1749e2..04efe93 100644 --- a/src/main.java +++ b/src/main.java @@ -19,18 +19,6 @@ public class main { player = start.getPlayer(); } - public void warehouse(Warehouse warehouse){ - warehouse.setPlayer(player); - //warehouse.intialize(); - player = warehouse.getPlayer(); - } - - public void bank(Bank bank){ - bank.setPlayer(player); - //warehouse.intialize(); - player = bank.getPlayer(); - } - public static void main(String[] args) { main main = new main(); TaipanShop littyShop = new TaipanShop(main.getPlayer());