Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Wargames
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sondre Malerud
Wargames
Commits
25703b49
Commit
25703b49
authored
3 years ago
by
Sondre Malerud
Browse files
Options
Downloads
Patches
Plain Diff
Updated javadoc
parent
6e06d4e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/no/ntnu/sondrmal/wargames/view/PreGamePane.java
+8
-5
8 additions, 5 deletions
...main/java/no/ntnu/sondrmal/wargames/view/PreGamePane.java
with
8 additions
and
5 deletions
src/main/java/no/ntnu/sondrmal/wargames/view/PreGamePane.java
+
8
−
5
View file @
25703b49
...
...
@@ -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
{
//
n
ormal speed is updating health bar every 150ms.
//
N
ormal speed is updating health bar every 150ms.
if
(
System
.
currentTimeMillis
()
<
speedUpTime
)
Thread
.
sleep
(
150
);
//
i
f loop goes for more than 5 seconds the health bar will now update every 30ms.
//
I
f 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
();
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment