Skip to content
Snippets Groups Projects
Commit 25703b49 authored by Sondre Malerud's avatar Sondre Malerud :coffee:
Browse files

Updated javadoc

parent 6e06d4e1
No related branches found
No related tags found
No related merge requests found
......@@ -210,7 +210,6 @@ public class PreGamePane extends View {
}
}
Battle battle = new Battle(ally, enemy);
SimulateController.getInstance().setAllyHealth(ally.getTotalHealth());
SimulateController.getInstance().setAllyTotalHealth(ally.getTotalHealth());
......@@ -218,13 +217,16 @@ public class PreGamePane extends View {
SimulateController.getInstance().setEnemyHealth(enemy.getTotalHealth());
SimulateController.getInstance().setEnemyTotalHealth(enemy.getTotalHealth());
// In order to update visually in real-time we need to start another thread, or else the application will
// freeze and wait until the entire code is finished running.
new Thread(() -> {
long currentTime = System.currentTimeMillis();
long speedUpTime = currentTime + 5000; //if loop goes for more than 5 seconds it will speed up
long speedUpTime = currentTime + 5000; // If loop goes for more than 5 seconds it will speed up.
startButton.setDisable(true); // Makes sure you cannot run multiple battles at once.
while (battle.simulateSingleAttack() == null) {
Platform.runLater(() -> {
//Makes sure the winning army will have _some_ visible health points even if they are very low
// Makes sure the winning army will have _some_ visible health points even if they are very low.
if (SimulateController.allyHealth == 0) {
allyHealthBar.setProgress((double) SimulateController.allyHealth / SimulateController.allyTotalHealth);
enemyHealthBar.setProgress(Math.max((0.05), (double) SimulateController.enemyHealth / SimulateController.enemyTotalHealth));
......@@ -234,10 +236,10 @@ public class PreGamePane extends View {
}
});
try {
//normal speed is updating health bar every 150ms.
// Normal speed is updating health bar every 150ms.
if (System.currentTimeMillis() < speedUpTime) Thread.sleep(150);
//if loop goes for more than 5 seconds the health bar will now update every 30ms.
// If loop goes for more than 5 seconds the health bar will now update every 30ms.
else {
Thread.sleep(30);
}
......@@ -248,6 +250,7 @@ public class PreGamePane extends View {
}
winnerText.setText("WINNER: " + battle.simulateSingleAttack().getName().toUpperCase() + "\n\nSELECT ANOTHER TERRAIN AND \nPRESES START TO TRY AGAIN");
winnerText.setId("normal-text");
startButton.setDisable(false); // Enables in case user wants to run another battle simulation.
}).start();
});
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment