Fixed loop problem ShipwarfareGUI
This commit is contained in:
@@ -46,7 +46,6 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String args[]) {
|
public static void main(String args[]) {
|
||||||
launch(args);
|
launch(args);
|
||||||
}
|
}
|
||||||
@@ -58,6 +57,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
private int startingLittyShips = 0;
|
private int startingLittyShips = 0;
|
||||||
private int howMuchRun = 0;
|
private int howMuchRun = 0;
|
||||||
private String pirateName = "Liu Yen";
|
private String pirateName = "Liu Yen";
|
||||||
|
private Boolean isScreenFull = false;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -379,7 +379,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
int exitValue = 0;
|
int exitValue = 0;
|
||||||
|
|
||||||
//Player volley
|
//Player volley
|
||||||
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++) {
|
||||||
@@ -389,7 +389,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
numOfPeasantShips--;
|
numOfPeasantShips--;
|
||||||
if (numOfPeasantShips <= 0) {
|
if (numOfPeasantShips <= 0) {
|
||||||
exitValue = 1;
|
exitValue = 1;
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
hitCounter++;
|
hitCounter++;
|
||||||
} else {
|
} else {
|
||||||
@@ -398,7 +398,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
//continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
report.setText(String.format("Report: Ships we hit: %d Shots missed: %d", hitCounter,missCounter));
|
report.setText(String.format("Report: Ships we hit: %d Shots missed: %d", hitCounter,missCounter));
|
||||||
@@ -411,7 +411,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
if (numOfPeasantShips <= 0) {
|
if (numOfPeasantShips <= 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;
|
||||||
@@ -441,7 +441,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
if (player.getHP() <= 0) {
|
if (player.getHP() <= 0) {
|
||||||
exitValue = 2;
|
exitValue = 2;
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
if(gunFrustration==true){
|
if(gunFrustration==true){
|
||||||
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
|
gunsLeftOrTaken.setText(String.format("Dang it! We only have %d guns left", player.getGuns()));
|
||||||
@@ -464,7 +464,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
chooseFightOrRun.setText("Couldn't run away");
|
chooseFightOrRun.setText("Couldn't run away");
|
||||||
} else {
|
} else {
|
||||||
exitValue = 3;
|
exitValue = 3;
|
||||||
break;
|
//break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -476,7 +476,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
if (exitValue == 1) {
|
if (exitValue == 1) {
|
||||||
@@ -537,7 +537,7 @@ public class ShipWarfareGUI extends Application {
|
|||||||
|
|
||||||
public void start(Stage stage) throws Exception {
|
public void start(Stage stage) throws Exception {
|
||||||
setNumOfPeasantShips(numOfShips());
|
setNumOfPeasantShips(numOfShips());
|
||||||
|
player.setGuns(5);
|
||||||
|
|
||||||
BorderPane BorderPane = new BorderPane();
|
BorderPane BorderPane = new BorderPane();
|
||||||
|
|
||||||
@@ -621,27 +621,11 @@ public class ShipWarfareGUI extends Application {
|
|||||||
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
fightButton.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
@Override
|
@Override
|
||||||
public void handle(ActionEvent event) {
|
public void handle(ActionEvent event) {
|
||||||
counter++;
|
|
||||||
if (counter == 1) {
|
|
||||||
|
|
||||||
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
chooseFightOrRun.setText("Ohh, Fight ehh?");
|
||||||
try {
|
try {
|
||||||
destroyPeasantShipsOrEscape();
|
destroyPeasantShipsOrEscape();
|
||||||
}
|
}
|
||||||
catch(Exception e){
|
catch(Exception e){}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
if (counter == 2) {
|
|
||||||
System.out.println("You pressed the button twice.");
|
|
||||||
fightButton.setVisible(false);
|
|
||||||
runButton.setVisible(false);
|
|
||||||
fightButton.setDisable(true);
|
|
||||||
runButton.setDisable(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user