diff --git a/src/Player.java b/src/Player.java index d4a159d..08278f2 100644 --- a/src/Player.java +++ b/src/Player.java @@ -135,8 +135,9 @@ public class Player { if (debt >= 0) { this.debt = debt; } + } - public void gameOver() { + public void gameOver(){ System.out.flush(); System.out.println("Game over"); } diff --git a/src/ShipWarfare.java b/src/ShipWarfare.java index ebcf9c0..49b10eb 100644 --- a/src/ShipWarfare.java +++ b/src/ShipWarfare.java @@ -11,13 +11,29 @@ public class ShipWarfare extends Player { private int startingLittyShips =0; private int howMuchRun = 0; private String pirateName = "Liu Yen"; + 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 Merchant ships\nCurrently our ship status is %d%%\n", getMoney(), numOfPeasantShips, getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.getHP()); fightOrRunMessage(); while (true) { @@ -51,7 +67,7 @@ public class ShipWarfare extends Player { public void littyFleetAttack() throws Exception { Scanner userResponse = new Scanner(System.in); setNumOfLittyShips(numOfShips()); - System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", getMoney(), numOfLittyShips, pirateName, getHP()); + System.out.printf("By Golly! We have $%,d and are being attacked by %d of %s's ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfLittyShips, pirateName, player.getHP()); fightOrRunMessage(); while (true) { String response = userResponse.nextLine(); @@ -83,7 +99,7 @@ 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()); } @@ -114,16 +130,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; } @@ -155,7 +171,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(3) + 1; if (hitOrMiss == 1) { @@ -205,23 +221,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(15))); + player.setHP(player.getHP() - (1 + randomValue.nextInt(15))); } - 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)\n", getGuns()); + System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); String response = userInput.nextLine(); if (response.equalsIgnoreCase("r")) { @@ -238,16 +254,16 @@ 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()); calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300; - setMoney(getMoney() + calculateLoot); + player.setMoney(player.getMoney() + calculateLoot); System.out.printf("We got $%,d!\n", calculateLoot); return true; } else if (exitValue == 2) { 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; @@ -267,7 +283,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) { @@ -314,23 +330,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)\n", getGuns()); + System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)\n", player.getGuns()); String response = userInput.nextLine(); if (response.equalsIgnoreCase("r")) { @@ -347,16 +363,16 @@ 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()); calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100; - setMoney(getMoney() + calculateLoot); + player.setMoney(player.getMoney() + calculateLoot); System.out.printf("We got $%,d!", calculateLoot); return true; } else if (exitValue == 2) { 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; @@ -364,11 +380,5 @@ public class ShipWarfare extends Player { } - - public static void main(String[] args) throws Exception { - ShipWarfare littyObject = new ShipWarfare(); - littyObject.littyFleetAttack(); - } - }