Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
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
Carl Gützkow
Wargames
Commits
c9f3aa82
Commit
c9f3aa82
authored
3 years ago
by
Carl Gützkow
Browse files
Options
Downloads
Patches
Plain Diff
enhance: battle simulate name refactor and next boolean when selecting attacker
parent
6ee0553d
No related branches found
No related tags found
No related merge requests found
Pipeline
#183926
passed
3 years ago
Stage: build
Stage: test
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/java/edu/ntnu/idatt2001/carljgu/battle/Battle.java
+17
-18
17 additions, 18 deletions
src/main/java/edu/ntnu/idatt2001/carljgu/battle/Battle.java
with
17 additions
and
18 deletions
src/main/java/edu/ntnu/idatt2001/carljgu/battle/Battle.java
+
17
−
18
View file @
c9f3aa82
...
...
@@ -96,30 +96,29 @@ public class Battle {
public
Army
simulate
()
{
if
(
winner
!=
null
)
throw
new
UnsupportedOperationException
(
"Simulation has already been run"
);
while
(
armyOne
.
hasUnits
()
&&
armyTwo
.
hasUnits
())
{
Army
a
ttackingArmy
;
Army
d
efendingArmy
;
Army
initialA
ttackingArmy
;
Army
initialD
efendingArmy
;
int
index
=
new
Random
().
nextInt
(
2
);
if
(
index
==
0
)
{
attackingArmy
=
armyOne
;
defendingArmy
=
armyTwo
;
if
(
new
Random
().
nextBoolean
())
{
initialAttackingArmy
=
armyOne
;
initialDefendingArmy
=
armyTwo
;
}
else
{
a
ttackingArmy
=
armyTwo
;
d
efendingArmy
=
armyOne
;
initialA
ttackingArmy
=
armyTwo
;
initialD
efendingArmy
=
armyOne
;
}
Unit
a
ttacker
=
a
ttackingArmy
.
getRandom
();
Unit
d
efender
=
d
efendingArmy
.
getRandom
();
Unit
initialA
ttacker
=
initialA
ttackingArmy
.
getRandom
();
Unit
initialD
efender
=
initialD
efendingArmy
.
getRandom
();
int
damageDealt
=
a
ttacker
.
attack
(
d
efender
,
terrain
);
attackLog
.
add
(
attackStringRepresentation
(
damageDealt
,
a
ttacker
,
d
efender
,
a
ttackingArmy
,
d
efendingArmy
));
if
(
d
efender
.
getHealth
()
<=
0
)
{
d
efendingArmy
.
remove
(
d
efender
);
int
damageDealt
=
initialA
ttacker
.
attack
(
initialD
efender
,
terrain
);
attackLog
.
add
(
attackStringRepresentation
(
damageDealt
,
initialA
ttacker
,
initialD
efender
,
initialA
ttackingArmy
,
initialD
efendingArmy
));
if
(
initialD
efender
.
getHealth
()
<=
0
)
{
initialD
efendingArmy
.
remove
(
initialD
efender
);
}
else
{
damageDealt
=
d
efender
.
attack
(
a
ttacker
,
terrain
);
attackLog
.
add
(
attackStringRepresentation
(
damageDealt
,
d
efender
,
a
ttacker
,
d
efendingArmy
,
a
ttackingArmy
));
if
(
a
ttacker
.
getHealth
()
<=
0
)
a
ttackingArmy
.
remove
(
a
ttacker
);
damageDealt
=
initialD
efender
.
attack
(
initialA
ttacker
,
terrain
);
attackLog
.
add
(
attackStringRepresentation
(
damageDealt
,
initialD
efender
,
initialA
ttacker
,
initialD
efendingArmy
,
initialA
ttackingArmy
));
if
(
initialA
ttacker
.
getHealth
()
<=
0
)
initialA
ttackingArmy
.
remove
(
initialA
ttacker
);
}
}
...
...
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