Made ShipWarfare easier to access by ShipWarfareGUI
This commit is contained in:
Binary file not shown.
@@ -49,7 +49,7 @@ public class ShipWarfare {
|
|||||||
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 Merchant ships\nCurrently our ship status is %d%%\n", player.getMoney(), numOfPeasantShips, player.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(), getNumOfPeasantShips(), player.getHP());
|
||||||
|
|
||||||
fightOrRunMessage();
|
fightOrRunMessage();
|
||||||
while (true) {
|
while (true) {
|
||||||
@@ -82,6 +82,38 @@ public class ShipWarfare {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getNumOfPeasantShips() {
|
||||||
|
return numOfPeasantShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNumOfLittyShips() {
|
||||||
|
return numOfLittyShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isUserAttacks() {
|
||||||
|
return userAttacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartingPeasantShips() {
|
||||||
|
return startingPeasantShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getStartingLittyShips() {
|
||||||
|
return startingLittyShips;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getHowMuchRun() {
|
||||||
|
return howMuchRun;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPirateName() {
|
||||||
|
return pirateName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserAttacks(boolean userAttacks) {
|
||||||
|
this.userAttacks = userAttacks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
|
* This fleet is difficult to defeat as a maximum of 10 ships can run away each volley, they can tank hits
|
||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
@@ -89,12 +121,12 @@ public class ShipWarfare {
|
|||||||
public void littyFleetAttack() throws Exception {
|
public void littyFleetAttack() throws Exception {
|
||||||
Scanner userResponse = new Scanner(System.in);
|
Scanner userResponse = new Scanner(System.in);
|
||||||
setNumOfLittyShips(numOfShips());
|
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", player.getMoney(), numOfLittyShips, pirateName, player.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(), getNumOfLittyShips(), getPirateName(), player.getHP());
|
||||||
fightOrRunMessage();
|
fightOrRunMessage();
|
||||||
while (true) {
|
while (true) {
|
||||||
String response = userResponse.nextLine();
|
String response = userResponse.nextLine();
|
||||||
if (response.equalsIgnoreCase("f")) {
|
if (response.equalsIgnoreCase("f")) {
|
||||||
userAttacks = true;
|
setUserAttacks(true);
|
||||||
System.out.println("Ohh, fight ehh?");
|
System.out.println("Ohh, fight ehh?");
|
||||||
boolean winOrLose = destroyLittyShipsOrEscape();
|
boolean winOrLose = destroyLittyShipsOrEscape();
|
||||||
if (winOrLose == true) {
|
if (winOrLose == true) {
|
||||||
@@ -193,7 +225,7 @@ public class ShipWarfare {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public boolean runFromShips() {
|
public boolean runFromShips() {
|
||||||
userAttacks = false;
|
setUserAttacks(false);
|
||||||
Random randomValue = new Random();
|
Random randomValue = new Random();
|
||||||
int runSuccessChance = randomValue.nextInt(2) + 1;
|
int runSuccessChance = randomValue.nextInt(2) + 1;
|
||||||
if (runSuccessChance == 2) {
|
if (runSuccessChance == 2) {
|
||||||
@@ -204,6 +236,10 @@ public class ShipWarfare {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setHowMuchRun(int howMuchRun) {
|
||||||
|
this.howMuchRun = howMuchRun;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The user faces off against the litty ships and either prevails, dies, or runs away
|
* The user faces off against the litty ships and either prevails, dies, or runs away
|
||||||
* The loot for defeating a litty fleet is much higher than that of a peasant one
|
* The loot for defeating a litty fleet is much higher than that of a peasant one
|
||||||
@@ -223,11 +259,11 @@ public class ShipWarfare {
|
|||||||
while (exitValue == 0) {
|
while (exitValue == 0) {
|
||||||
if (player.getGuns() > 0) {
|
if (player.getGuns() > 0) {
|
||||||
for (int j = 0; j < player.getGuns(); j++) {
|
for (int j = 0; j < player.getGuns(); j++) {
|
||||||
if (userAttacks == true) {
|
if (isUserAttacks()==true) {
|
||||||
int hitOrMiss = randomValue.nextInt(3) + 1;
|
int hitOrMiss = randomValue.nextInt(3) + 1;
|
||||||
if (hitOrMiss == 1) {
|
if (hitOrMiss == 1) {
|
||||||
numOfLittyShips--;
|
setNumOfPeasantShips(getNumOfPeasantShips()-1);
|
||||||
if (numOfLittyShips <= 0) {
|
if (getNumOfLittyShips() <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -252,28 +288,28 @@ public class ShipWarfare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (numOfLittyShips <= 0) {
|
if (getNumOfLittyShips() <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (player.getGuns() > 0) {
|
if (player.getGuns() > 0) {
|
||||||
if (chanceOfEnemyRun == 2) {
|
if (chanceOfEnemyRun == 2) {
|
||||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||||
howMuchRun = randomValue.nextInt(10) + 1;
|
setHowMuchRun(randomValue.nextInt(10) + 1);
|
||||||
if (howMuchRun != 0 && howMuchRun < numOfLittyShips) {
|
if (getHowMuchRun() != 0 && getHowMuchRun() < getNumOfLittyShips()) {
|
||||||
|
|
||||||
|
|
||||||
setNumOfLittyShips(numOfLittyShips - howMuchRun);
|
setNumOfLittyShips(getNumOfLittyShips() - getHowMuchRun());
|
||||||
if (userAttacks == true) {
|
if (isUserAttacks()==true) {
|
||||||
System.out.printf("Cowards! %d ships ran away %s!\n", howMuchRun, player.getName());
|
System.out.printf("Cowards! %d ships ran away %s!\n", getHowMuchRun(), player.getName());
|
||||||
} else {
|
} else {
|
||||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
System.out.printf("Escaped %d of them!\n", getHowMuchRun());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("%d ships remaining\n", numOfLittyShips);
|
System.out.printf("%d ships remaining\n", getNumOfLittyShips());
|
||||||
System.out.println("Oh no, they are taking the offensive!");
|
System.out.println("Oh no, they are taking the offensive!");
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
//Computer volley
|
//Computer volley
|
||||||
@@ -290,8 +326,8 @@ public class ShipWarfare {
|
|||||||
}
|
}
|
||||||
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
if (userAttacks == false) {
|
if (isUserAttacks() == false) {
|
||||||
userAttacks = true;
|
setUserAttacks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
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());
|
||||||
@@ -315,7 +351,7 @@ public class ShipWarfare {
|
|||||||
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", player.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());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
calculateLoot = (randomValue.nextInt(startingLittyShips) + startingLittyShips) * 300;
|
calculateLoot = (randomValue.nextInt(getStartingLittyShips()) + getStartingLittyShips()) * 300;
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
player.setMoney(player.getMoney() + calculateLoot);
|
||||||
System.out.printf("We got $%,d!\n", calculateLoot);
|
System.out.printf("We got $%,d!\n", calculateLoot);
|
||||||
delayForSeconds(2);
|
delayForSeconds(2);
|
||||||
@@ -340,6 +376,7 @@ public class ShipWarfare {
|
|||||||
* @throws Exception in case of errors due to the delay
|
* @throws Exception in case of errors due to the delay
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
public boolean destroyPeasantShipsOrEscape() throws Exception {
|
||||||
int calculateLoot = 0;
|
int calculateLoot = 0;
|
||||||
int chanceOfEnemyRun = 0;
|
int chanceOfEnemyRun = 0;
|
||||||
@@ -354,11 +391,11 @@ public class ShipWarfare {
|
|||||||
if (player.getGuns() > 0) {
|
if (player.getGuns() > 0) {
|
||||||
|
|
||||||
for (int j = 0; j < player.getGuns(); j++) {
|
for (int j = 0; j < player.getGuns(); j++) {
|
||||||
if (userAttacks == true) {
|
if (isUserAttacks()==true) {
|
||||||
int hitOrMiss = randomValue.nextInt(2) + 1;
|
int hitOrMiss = randomValue.nextInt(2) + 1;
|
||||||
if (hitOrMiss == 2) {
|
if (hitOrMiss == 2) {
|
||||||
numOfPeasantShips--;
|
setNumOfPeasantShips(getNumOfPeasantShips()-1);
|
||||||
if (numOfPeasantShips <= 0) {
|
if (getNumOfPeasantShips() <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -382,28 +419,28 @@ public class ShipWarfare {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (numOfPeasantShips <= 0) {
|
if (getNumOfPeasantShips() <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (player.getGuns() > 0) {
|
if (player.getGuns() > 0) {
|
||||||
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
chanceOfEnemyRun = randomValue.nextInt(2) + 1;
|
||||||
if (chanceOfEnemyRun == 2) {
|
if (chanceOfEnemyRun == 2) {
|
||||||
howMuchRun = randomValue.nextInt(15) + 1;
|
setHowMuchRun(randomValue.nextInt(15) + 1);
|
||||||
if (howMuchRun != 0 && howMuchRun < numOfPeasantShips) {
|
if (getHowMuchRun() != 0 && getHowMuchRun() < getNumOfPeasantShips()) {
|
||||||
|
|
||||||
|
|
||||||
setNumOfPeasantShips(numOfPeasantShips - howMuchRun);
|
setNumOfPeasantShips(getNumOfPeasantShips() - getHowMuchRun());
|
||||||
if (userAttacks == true) {
|
if ( isUserAttacks()==true) {
|
||||||
System.out.printf("Ahhh, %d ships ran away %s!\n", howMuchRun, player.getName());
|
System.out.printf("Ahhh, %d ships ran away %s!\n", getHowMuchRun(), player.getName());
|
||||||
} else {
|
} else {
|
||||||
System.out.printf("Escaped %d of them!\n", howMuchRun);
|
System.out.printf("Escaped %d of them!\n", getHowMuchRun());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.printf("%d ships remaining\n", numOfPeasantShips);
|
System.out.printf("%d ships remaining\n", getNumOfPeasantShips());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
System.out.println("Oh no, they are taking the offensive!");
|
System.out.println("Oh no, they are taking the offensive!");
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
@@ -421,8 +458,8 @@ public class ShipWarfare {
|
|||||||
}
|
}
|
||||||
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
System.out.printf("EEK, our current ship status is %d%% \n", player.getHP());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
if (userAttacks == false) {
|
if (isUserAttacks()==false) {
|
||||||
userAttacks = true;
|
setUserAttacks(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
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());
|
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());
|
||||||
@@ -444,7 +481,7 @@ public class ShipWarfare {
|
|||||||
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", player.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());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
calculateLoot = (randomValue.nextInt(startingPeasantShips) + startingPeasantShips) * 100;
|
calculateLoot = (randomValue.nextInt(getStartingPeasantShips()) + getStartingPeasantShips()) * 100;
|
||||||
player.setMoney(player.getMoney() + calculateLoot);
|
player.setMoney(player.getMoney() + calculateLoot);
|
||||||
System.out.printf("We got $%,d!", calculateLoot);
|
System.out.printf("We got $%,d!", calculateLoot);
|
||||||
delayForSeconds(2);
|
delayForSeconds(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user