diff --git a/out/production/TaipanClone/ShipWarfare.class b/out/production/TaipanClone/ShipWarfare.class index ed2afde..26c4c4c 100644 Binary files a/out/production/TaipanClone/ShipWarfare.class and b/out/production/TaipanClone/ShipWarfare.class differ diff --git a/src/Player.java b/src/Player.java index cab779c..32f46d8 100644 --- a/src/Player.java +++ b/src/Player.java @@ -419,9 +419,10 @@ public class Player { } /** - * Method to indicate that you have lost the game - * - */ + * Method to indicate that you have lost the game. If the player has lost, console will be cleared and will only + * show the statement "Game Over". After showing the message the game closes. + * + **/ public void gameOver(){ System.out.flush(); diff --git a/src/Start.java b/src/Start.java index bdf7017..8a86938 100644 --- a/src/Start.java +++ b/src/Start.java @@ -4,9 +4,9 @@ public class Start private Player player; /** - * getter method for obtaining a player object. + * gets the player instance variable. The method returns a copy of the instance variable for encapsulation purposes. * - * @return returns object of the class Player + * @return playerDummy -- playerDummy is a copy of the player instance variable. */ public Player getPlayer() { Player playerTemp = new Player(player); @@ -14,9 +14,9 @@ public class Start } /** - * setter method that takes in a Player object as an argument. + * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes. * - * @param player takes object of the class Player as an argument + * @param player is a Player object that will replace the current instance of the player instance variable. */ public void setPlayer(Player player) { Player playerTemp = new Player(player); diff --git a/src/TaipanShop.java b/src/TaipanShop.java index 7d7cabd..9e8af02 100644 --- a/src/TaipanShop.java +++ b/src/TaipanShop.java @@ -14,9 +14,7 @@ public class TaipanShop { public void retire(){ player.setRetire(true); System.out.println("You win!"); - if(player.playAgain()){ - setPlayer(new Player()); - } + System.exit(0); } /** diff --git a/src/Travel.java b/src/Travel.java index d658e4d..4ae62b6 100644 --- a/src/Travel.java +++ b/src/Travel.java @@ -5,21 +5,42 @@ public class Travel { private Player player; + /** + * sets the player instance variable equal to a copy of the parameter -- a copy is used for encapsulation purposes. + * + * @param player is a Player object that will replace the current instance of the player instance variable. + */ public void setPlayer(Player player) { Player playerDummy = new Player(player); this.player = playerDummy; } + /** + * getter method for obtaining a player object. + * + * @return returns player object + */ public Player getPlayer() { Player playerDummy = new Player(player); return playerDummy; } + /** + * constructor; only runs when a Player object is provided. The constructor is fully encapsulated. + * + * @param player is a Player object that will be copied and the player instance variable is set to the copy. + */ public Travel(Player player) { Player playerDummy = new Player(player); this.player = playerDummy; } + /** + * When provided a location number: the method returns a print statement stating the location's name and call another + * method to change the location of the Player object. + * + * @param locationOfTravel is a Player object that will be copied and the player instance variable is set to the copy. + */ private void seaAtlas(int locationOfTravel) { switch (locationOfTravel) { case 1: @@ -53,25 +74,43 @@ public class Travel { } } + /** + * Based on random chance either attacks the player with enemy ships, throws them to a different location or does nothing. + * + * @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed + * by a typhoon. + **/ private void randomEventSea(int locationOfTravel) throws Exception { Random rand = new Random(); - int randGenNum = rand.nextInt(3) + 1; + int randGenNum = rand.nextInt(4) + 1; if (randGenNum == 1) { peasantFleet(); - } else if (randGenNum == 2) { + }else if (randGenNum == 2){ + littyFleet(); + }else if (randGenNum == 3) { disaster(locationOfTravel); + System.out.println("We made it!"); } - System.out.println("We made it!"); } + /** + * Based on random chance either throws the player character off course, or continues them on their way to their + * destination. + * + * @param locationOfTravel is used to see where the player is going to travel, just in case their location is changed + * by a typhoon. + **/ private void disaster(int locationOfTravel) { + //Tells player that there is a storm approaching. System.out.print("Storm " + player.getName() + "! "); Random rand = new Random(); int randGenNum = rand.nextInt(5) + 1; + //If the player lands within this range, nothing happens to them + //Else they randomly get thrown into a location they weren't planning on going to(Anything but location of Travel). if (randGenNum <= 2) { System.out.println(" We made it through!"); - } else { + }else { while (randGenNum == locationOfTravel) { randGenNum = rand.nextInt(7) + 1; if (randGenNum != locationOfTravel) { @@ -82,39 +121,67 @@ public class Travel { } } + /** + * To use the peasant fleet class while still maintaining encapsulation we have to create a ShipWarefare object and + * run the method from there. After the method has been run we can update the player object in this class. + * + **/ public void peasantFleet() throws Exception { ShipWarfare attackShip = new ShipWarfare(player); attackShip.peasantFleetAttack(); player = attackShip.getPlayer(); } + /** + * To use the litty fleet class while still maintaining encapsulation we have to create a ShipWarefare object and + * run the method from there. After the method has been run we can update the player object in this class. + * + **/ + public void littyFleet() throws Exception { + ShipWarfare attackShip = new ShipWarfare(player); + attackShip.littyFleetAttack(); + player = attackShip.getPlayer(); + } + + /** + *Used to travel between different areas inside of the game world. + * If the player's inventory is too full it won't run. + * Also calculates loan and bank interest between the jumps between islands. + **/ public void travelTo() { Scanner keyboard = new Scanner(System.in); String response; int tempInt; boolean hasTraveled = false; - while (true) { - 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?"); + //Only lets the player leave the port if their inventory is greater than or equal to the sum of the items in the inventory. + if(player.getCargoSpace() >= (player.getOpiumHeld()+ (player.getGuns()*10)+player.getSilkHeld() + player.getArmsHeld() + player.getGeneralHeld())){ + while (true) { + 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 + " " + player.getLocation()); - if (tempInt != player.getLocation()) { - 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?"); - } - if (hasTraveled) { - break; + response = keyboard.nextLine(); + //Just in case the player types something that was not intended. It will refresh the question and ask it again + try { + tempInt = Integer.parseInt(response); + //Makes sure you can't travel to your own location. + if (tempInt != player.getLocation()) { + 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?"); + } + if (hasTraveled) { + break; + } } } + else{ + System.out.println(player.getName() + " the cargo is too heavy! We can't set sail!"); + } } } diff --git a/src/main.java b/src/main.java index f45a119..e297598 100644 --- a/src/main.java +++ b/src/main.java @@ -40,9 +40,7 @@ public class main { /** * Updates main class with player data and starts the game. * The game will only run as long as the player has not retired or has been destroyed. - * */ - public static void main(String[] args) { main main = new main(); TaipanShop littyShop = new TaipanShop(main.getPlayer());