Perhaps done basic ship warfare? (still must add Liu yen difficulty, ships running away, and Loot)

This commit is contained in:
KahootChampion
2019-02-20 16:07:44 -07:00
parent 4598d219c7
commit 03b08e4de3
2 changed files with 70 additions and 72 deletions

View File

@@ -2,13 +2,13 @@ public class Player {
private String name = "Taipan"; private String name = "Taipan";
private int bank = 0; private int bank = 0;
private int money = 100000000; private int money = 1000;
private int opiumHeld = 0; private int opiumHeld = 0;
private int silkHeld = 0; private int silkHeld = 0;
private int generalHeld = 0; private int generalHeld = 0;
private int armsHeld = 0; private int armsHeld = 0;
private int location = 1; private int location = 1;
private int guns = 6; private int guns = 3;
private int HP = 100; private int HP = 100;
@@ -116,8 +116,13 @@ public class Player {
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
ShipWarfare littyboi = new ShipWarfare(); ShipWarfare littyWarfare = new ShipWarfare();
TaipanShop littyShop = new TaipanShop(); TaipanShop littyShop = new TaipanShop();
littyShop.shop();
littyWarfare.peasantFleetAttack();
littyShop.shop(); littyShop.shop();
} }

View File

@@ -11,7 +11,7 @@ public class ShipWarfare extends Player {
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 \nwe are being attacked by %d ships\n", getMoney(), getNumOfPeasantShips()); 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());
fightOrRunMessage(); fightOrRunMessage();
while (true) { while (true) {
String response = userResponse.nextLine(); String response = userResponse.nextLine();
@@ -25,11 +25,12 @@ public class ShipWarfare extends Player {
} else if (response.equalsIgnoreCase("r")) { } else if (response.equalsIgnoreCase("r")) {
runFromShips();
if (runFromShips() == false) { if (runFromShips() == false) {
System.out.println("Couldn't run away!"); System.out.println("Couldn't run away!");
destroyShipsOrEscape(getNumOfPeasantShips()); if(destroyShipsOrEscape(getNumOfPeasantShips()))
break;
} else { } else {
System.out.println("Phew! Got away safely");
break; break;
} }
@@ -101,87 +102,80 @@ public class ShipWarfare extends Player {
int exitValue = 0; int exitValue = 0;
//Player volley //Player volley
if (exitValue == 0) { while (exitValue == 0) {
while (exitValue == 0) { for (int j = 0; j < getGuns(); j++) {
for (int i = 0; i < numOfPeasantShips; i++) { if (userAttacks == true) {
int hitOrMiss = randomValue.nextInt(2) + 1;
for (int j = 0; j < getGuns(); j++) { if (hitOrMiss == 2) {
if (userAttacks == true) { numOfPeasantShips--;
int hitOrMiss = randomValue.nextInt(2) + 1; if (numOfPeasantShips <= 0) {
if (hitOrMiss == 2) { exitValue = 1;
numOfPeasantShips--;
if (numOfPeasantShips <= 0) {
exitValue = 1;
break;
}
System.out.println("Got eem");
delayForASecond();
} else {
System.out.println("ARRG! We missed captain");
delayForASecond();
}
} else {
continue;
}
}
if (numOfPeasantShips <= 0) {
exitValue = 1;
break;
}
System.out.printf("%d ships remaining\n", getNumOfPeasantShips());
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1);
System.out.println("Dang it! They destroyed one of our guns");
} else {
setHP(getHP() - (1 + randomValue.nextInt(10)));
}
if (getHP() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, we have %d health left\n", 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 guns left)", getGuns());
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
runFromShips();
if (runFromShips() == false) {
System.out.println("Couldn't run away");
} else {
exitValue = 3;
break; break;
} }
System.out.println("Got eem");
delayForASecond();
} else {
System.out.println("ARRG! We missed captain");
delayForASecond();
} }
} else {
continue;
} }
if (runFromShips() == true) { }
if (numOfPeasantShips <= 0) {
exitValue = 1;
break;
}
System.out.printf("%d ships remaining\n", getNumOfPeasantShips());
System.out.println("Oh no, they are taking the offensive!");
delayForASecond();
//Computer volley
int takeGunChance = randomValue.nextInt(4) + 1;
if (takeGunChance == 1 && getGuns() > 0) {
setGuns(getGuns() - 1);
System.out.println("Dang it! They destroyed one of our guns");
} else {
setHP(getHP() - (1 + randomValue.nextInt(10)));
}
if (getHP() <= 0) {
exitValue = 2;
break;
}
System.out.printf("EEK, our current ship status is %d%% \n", 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)", getGuns());
String response = userInput.nextLine();
if (response.equalsIgnoreCase("r")) {
if (runFromShips() == false) {
System.out.println("Couldn't run away");
} else {
exitValue = 3;
break; break;
} }
} }
} }
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 health\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", getHP());
return true; return true;
} else if (exitValue == 2) { } else if (exitValue == 2) {
gameOver(); gameOver();
return true; return true;
} else if (exitValue == 3) { } else if (exitValue == 3) {
System.out.printf("We made it out at %d health!\n", getHP()); System.out.printf("We made it out at %d%% ship status!\n", getHP());
return true; return true;
} }
return false; return false;
@@ -198,4 +192,3 @@ public class ShipWarfare extends Player {
} }