Update ShipWarfare.java
This commit is contained in:
@@ -2,16 +2,32 @@ import java.util.Scanner;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class ShipWarfare extends Player {
|
public class ShipWarfare{
|
||||||
|
|
||||||
private int numOfPeasantShips = 0;
|
private int numOfPeasantShips = 0;
|
||||||
private boolean userAttacks = true;
|
private boolean userAttacks = true;
|
||||||
|
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 {
|
public void peasantFleetAttack() throws Exception {
|
||||||
Scanner userResponse = new Scanner(System.in);
|
Scanner userResponse = new Scanner(System.in);
|
||||||
setNumOfPeasantShips(numOfShips());
|
setNumOfPeasantShips(numOfShips());
|
||||||
System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", getMoney(), getNumOfPeasantShips(),getHP());
|
System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfPeasantShips(),player.getHP());
|
||||||
|
System.out.printf("By Golly! We have $%,d and are being attacked by %d ships\nCurrently our ship status is %d%%\n", player.getMoney(), getNumOfPeasantShips(),player.getHP());
|
||||||
fightOrRunMessage();
|
fightOrRunMessage();
|
||||||
while (true) {
|
while (true) {
|
||||||
String response = userResponse.nextLine();
|
String response = userResponse.nextLine();
|
||||||
@@ -43,7 +59,8 @@ public class ShipWarfare extends Player {
|
|||||||
|
|
||||||
|
|
||||||
public void fightOrRunMessage() {
|
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());
|
||||||
|
System.out.printf("What do you want to do? Enter \"f\" to fight, and \"r\" to run (we have %d guns)", player.getGuns());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,16 +82,16 @@ public class ShipWarfare extends Player {
|
|||||||
int numOfShipsAttacking = 0;
|
int numOfShipsAttacking = 0;
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
|
|
||||||
if (getMoney() <= 100000) {
|
if (player.getMoney() <= 100000) {
|
||||||
//Minimum one ship will attack, maximum 20
|
//Minimum one ship will attack, maximum 20
|
||||||
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
numOfShipsAttacking = randomValue.nextInt(20) + 1;
|
||||||
} else if (getMoney() <= 200000) {
|
} else if (player.getMoney() <= 200000) {
|
||||||
//Minimum 30 Ships will attack, maximum 70
|
//Minimum 30 Ships will attack, maximum 70
|
||||||
numOfShipsAttacking = randomValue.nextInt(40) + 30;
|
numOfShipsAttacking = randomValue.nextInt(40) + 30;
|
||||||
} else if (getMoney() <= 500000) {
|
} else if (player.getMoney() <= 500000) {
|
||||||
//Minimum 50 ships will attack, maximum 140
|
//Minimum 50 ships will attack, maximum 140
|
||||||
numOfShipsAttacking = randomValue.nextInt(90) + 50;
|
numOfShipsAttacking = randomValue.nextInt(90) + 50;
|
||||||
} else if (getMoney() > 1000000) {
|
} else if (player.getMoney() > 1000000) {
|
||||||
//Minimum 100 ships will attack, maximum 300 ships
|
//Minimum 100 ships will attack, maximum 300 ships
|
||||||
numOfShipsAttacking = randomValue.nextInt(3) + 100;
|
numOfShipsAttacking = randomValue.nextInt(3) + 100;
|
||||||
}
|
}
|
||||||
@@ -103,7 +120,7 @@ public class ShipWarfare extends Player {
|
|||||||
|
|
||||||
//Player volley
|
//Player volley
|
||||||
while (exitValue == 0) {
|
while (exitValue == 0) {
|
||||||
for (int j = 0; j < getGuns(); j++) {
|
for (int j = 0; j < player.getGuns(); j++) {
|
||||||
if (userAttacks == true) {
|
if (userAttacks == true) {
|
||||||
int hitOrMiss = randomValue.nextInt(2) + 1;
|
int hitOrMiss = randomValue.nextInt(2) + 1;
|
||||||
if (hitOrMiss == 2) {
|
if (hitOrMiss == 2) {
|
||||||
@@ -136,23 +153,23 @@ public class ShipWarfare extends Player {
|
|||||||
delayForASecond();
|
delayForASecond();
|
||||||
//Computer volley
|
//Computer volley
|
||||||
int takeGunChance = randomValue.nextInt(4) + 1;
|
int takeGunChance = randomValue.nextInt(4) + 1;
|
||||||
if (takeGunChance == 1 && getGuns() > 0) {
|
if (takeGunChance == 1 && player.getGuns() > 0) {
|
||||||
setGuns(getGuns() - 1);
|
player.setGuns(player.getGuns() - 1);
|
||||||
System.out.println("Dang it! They destroyed one of our guns");
|
System.out.println("Dang it! They destroyed one of our guns");
|
||||||
} else {
|
} else {
|
||||||
setHP(getHP() - (1 + randomValue.nextInt(10)));
|
player.setHP(player.getHP() - (1 + randomValue.nextInt(10)));
|
||||||
}
|
}
|
||||||
if (getHP() <= 0) {
|
if (player.getHP() <= 0) {
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
break;
|
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();
|
delayForASecond();
|
||||||
if (userAttacks == false) {
|
if (userAttacks == false) {
|
||||||
userAttacks = true;
|
userAttacks = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)", getGuns());
|
System.out.printf("Shall we continue to fight? Enter \"f\" to fight, and \"r\" to run (We have %d gun(s) left)", player.getGuns());
|
||||||
|
|
||||||
String response = userInput.nextLine();
|
String response = userInput.nextLine();
|
||||||
if (response.equalsIgnoreCase("r")) {
|
if (response.equalsIgnoreCase("r")) {
|
||||||
@@ -169,13 +186,13 @@ public class ShipWarfare extends Player {
|
|||||||
|
|
||||||
|
|
||||||
if (exitValue == 1) {
|
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());
|
||||||
return true;
|
return true;
|
||||||
} else if (exitValue == 2) {
|
} else if (exitValue == 2) {
|
||||||
gameOver();
|
player.gameOver();
|
||||||
return true;
|
return true;
|
||||||
} else if (exitValue == 3) {
|
} 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 true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -185,10 +202,4 @@ public class ShipWarfare extends Player {
|
|||||||
//Type of ship implied to be Liu Yen fleet
|
//Type of ship implied to be Liu Yen fleet
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
ShipWarfare littyObject = new ShipWarfare();
|
|
||||||
littyObject.peasantFleetAttack();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user