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
|
||||
*
|
||||
* @param random random object is used
|
||||
* @param exitValue exit in order to know if user wins, loses, or flees
|
||||
* @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) {
|
||||
int hitOrMiss = random.nextInt(2) + 1;
|
||||
if (hitOrMiss == 2) {
|
||||
logic.setNumOfShips(logic.getNumOfShips() - 1);
|
||||
if (logic.getNumOfShips() <= 0) {
|
||||
exitValue = 1;
|
||||
return exitValue = 1;
|
||||
}
|
||||
System.out.println("Got eem");
|
||||
delayForSeconds(1);
|
||||
@@ -116,6 +118,8 @@ public class ShipWarfareText extends Player {
|
||||
|
||||
|
||||
}
|
||||
exitValue=0;
|
||||
return exitValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -153,10 +157,12 @@ public class ShipWarfareText extends Player {
|
||||
if (getGuns() > 0) {
|
||||
for (int j = 0; j < getGuns(); j++) {
|
||||
attackOrNot(randomValue, exitValue);
|
||||
|
||||
}
|
||||
if (exitValue == 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
} else {
|
||||
System.out.printf("%s! We don't have any GUNS!!!!\n", getName());
|
||||
delayForSeconds(1);
|
||||
@@ -253,4 +259,9 @@ public class ShipWarfareText extends Player {
|
||||
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