diff --git a/README.md b/README.md index 893c2b0..af45ed3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,12 @@ # TaipanClone Computer Science 233 project, Winter 2019 -To run the program, please go to src>start.java and run that program. +How to run: +If you are using intellij, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder in intellij. Also set up the SDK. Then, run main.java. + +If you are using the command line, extract "TaipanClone-master.zip", and open the "TaipanClone-master" folder. Open your terminal and change its directory to the "src" folder within "TaipanClone-master" folder. Then, type in "javac *.java", this compiles all the necessary files. Now, run main.java using "java main". + +Additional information: For input, the program usually takes the first letter of whichever option you need to select. Example: What would you like to buy? Valid inputs are "O" (for Opium), "S" (for Silk), "A" (for Arms), "G" (for General cargo). diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class new file mode 100644 index 0000000..a2e9449 Binary files /dev/null and b/out/production/TaipanClone/ShipWarfare.class differ diff --git a/src/Bank.java b/src/Bank.java index b76f423..5769d84 100644 --- a/src/Bank.java +++ b/src/Bank.java @@ -1,4 +1,3 @@ -import java.sql.SQLOutput; import java.util.Scanner; public class Bank{ diff --git a/src/Player.java b/src/Player.java index 8aa5f73..709c01e 100644 --- a/src/Player.java +++ b/src/Player.java @@ -211,6 +211,7 @@ public class Player { public void gameOver(){ System.out.flush(); System.out.println("Game over"); + System.exit(0); } } \ No newline at end of file diff --git a/src/Start.java b/src/Start.java index eafbf77..8f5f72a 100644 --- a/src/Start.java +++ b/src/Start.java @@ -3,22 +3,42 @@ public class Start { private Player player; + /** + * getter method for obtaining a player object. + * + * @return returns player object + */ public Player getPlayer() { Player playerTemp = new Player(player); return playerTemp; } + /** + * setter method that takes in a Player object as an argument. + * + * @param player object of the class Player + */ 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); } } - public void intialize() + + /** + * 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:"); @@ -46,6 +66,10 @@ public class Start } + /** + * Copy constructor. + * @param player object of the class Player + */ public Start(Player player) { Player playerTemp = new Player(player); diff --git a/src/loanShark.java b/src/loanShark.java index 4cfc87f..dc3732e 100644 --- a/src/loanShark.java +++ b/src/loanShark.java @@ -20,20 +20,37 @@ public class loanShark { 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(); - if(loanAsk <= 2*(player.getMoney() - player.getDebt())) { - player.setDebt(player.getDebt() + loanAsk); - player.setMoney(player.getMoney() + loanAsk); - } - //updated - else{ - System.out.println("Sorry you can't be loaned that much"); - break; - } String check; + Scanner keyboard = new Scanner(System.in); + System.out.println("Would you like to return money or borrow money?"); + check = keyboard.nextLine(); + 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); + }//updated + else if(returnAsk > player.getDebt()){ + System.out.println("You don't need to return that much!"); + }else{ + System.out.println("You can't return a negative amount."); + } + }else if(check.equalsIgnoreCase("b")){ + int loanAsk = 0; + System.out.println("Please enter how much you 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); + }//updated + else{ + System.out.println("Sorry you can't be loaned that much"); + break; + } + } + System.out.println("Would you like to do any other business? Y / N?"); check = keyboard.nextLine(); check = keyboard.nextLine(); @@ -46,4 +63,4 @@ public class loanShark { } } } -} \ No newline at end of file +} diff --git a/src/main.java b/src/main.java index 04efe93..25f4313 100644 --- a/src/main.java +++ b/src/main.java @@ -15,7 +15,7 @@ public class main { public void start(Start start){ start.setPlayer(player); - start.intialize(); + start.initialize(); player = start.getPlayer(); }