Fixed many issues with ShipWarfare text like the fact that the game wouldnt end when all ships were defeated until all shots had been fired
This commit is contained in:
@@ -95,17 +95,19 @@ public class ShipWarfareText extends Player {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ships either land a hit or do not
|
* Ships either land a hit or do not
|
||||||
* @param random random object is used
|
*
|
||||||
|
* @param random random object is used
|
||||||
* @param exitValue exit in order to know if user wins, loses, or flees
|
* @param exitValue exit in order to know if user wins, loses, or flees
|
||||||
* @throws Exception in case error is caused due to the delay
|
* @throws Exception in case error is caused due to the delay
|
||||||
|
* @return exitValue
|
||||||
*/
|
*/
|
||||||
public void attackOrNot(Random random, int exitValue) throws Exception {
|
public int attackOrNot(Random random, int exitValue) throws Exception {
|
||||||
if (userAttacks == true) {
|
if (userAttacks == true) {
|
||||||
int hitOrMiss = random.nextInt(2) + 1;
|
int hitOrMiss = random.nextInt(2) + 1;
|
||||||
if (hitOrMiss == 2) {
|
if (hitOrMiss == 2) {
|
||||||
logic.setNumOfShips(logic.getNumOfShips() - 1);
|
logic.setNumOfShips(logic.getNumOfShips() - 1);
|
||||||
if (logic.getNumOfShips() <= 0) {
|
if (logic.getNumOfShips() <= 0) {
|
||||||
exitValue = 1;
|
return exitValue = 1;
|
||||||
}
|
}
|
||||||
System.out.println("Got eem");
|
System.out.println("Got eem");
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
@@ -116,12 +118,14 @@ public class ShipWarfareText extends Player {
|
|||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
exitValue=0;
|
||||||
|
return exitValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ships either run away or we escape
|
* Ships either run away or we escape
|
||||||
*/
|
*/
|
||||||
public void shipsRunOrWeEscape(){
|
public void shipsRunOrWeEscape() {
|
||||||
if (howMuchRun != 0 && howMuchRun < logic.getNumOfShips()) {
|
if (howMuchRun != 0 && howMuchRun < logic.getNumOfShips()) {
|
||||||
logic.setNumOfShips(logic.getNumOfShips() - howMuchRun);
|
logic.setNumOfShips(logic.getNumOfShips() - howMuchRun);
|
||||||
if (userAttacks == true) {
|
if (userAttacks == true) {
|
||||||
@@ -152,11 +156,13 @@ public class ShipWarfareText extends Player {
|
|||||||
while (exitValue == 0) {
|
while (exitValue == 0) {
|
||||||
if (getGuns() > 0) {
|
if (getGuns() > 0) {
|
||||||
for (int j = 0; j < getGuns(); j++) {
|
for (int j = 0; j < getGuns(); j++) {
|
||||||
attackOrNot(randomValue,exitValue);
|
attackOrNot(randomValue, exitValue);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (exitValue == 1) {
|
if (exitValue == 1) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
||||||
delayForSeconds(1);
|
delayForSeconds(1);
|
||||||
@@ -253,4 +259,9 @@ public class ShipWarfareText extends Player {
|
|||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws Exception {
|
||||||
|
ShipWarfareText test = new ShipWarfareText(new Player());
|
||||||
|
test.peasantFleetAttack();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user