summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2016-01-24 11:12:05 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2016-01-24 11:12:05 +0100
commit7e4e99ae6cbd1df3acd94febad7d01122bcb8cc2 (patch)
tree96835f4445c55b157a14a8b5afc4b965589f4f70 /core/src
parentdb490703a07ebe1e293fb8dc6c952ed92132ebf2 (diff)
downloadRustAndDust-7e4e99ae6cbd1df3acd94febad7d01122bcb8cc2.zip
RustAndDust-7e4e99ae6cbd1df3acd94febad7d01122bcb8cc2.tar.gz
BattleCommon: add getWinner(int)
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/Battle00.java20
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java26
-rw-r--r--core/src/ch/asynk/rustanddust/game/battles/BattleTest.java21
3 files changed, 27 insertions, 40 deletions
diff --git a/core/src/ch/asynk/rustanddust/game/battles/Battle00.java b/core/src/ch/asynk/rustanddust/game/battles/Battle00.java
index 5a6a3eb..411b6aa 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/Battle00.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/Battle00.java
@@ -44,25 +44,7 @@ public class Battle00 extends BattleCommon
@Override
public Player getWinner()
{
- if (!abTurnDone())
- return null;
-
- if (gePlayer.unitsLeft() == 0)
- return usPlayer;
- if (usPlayer.unitsLeft() == 0)
- return gePlayer;
-
- if (gePlayer.getTurnDone() <= 8)
- return null;
-
- usPlayer.objectivesWon = map.objectivesCount(Army.US);
- gePlayer.objectivesWon = map.objectivesCount(Army.GE);
-
- if (usPlayer.objectivesWon >= gePlayer.objectivesWon) {
- return usPlayer;
- } else {
- return gePlayer;
- }
+ return getWinner(8);
}
@Override
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
index 6ea1046..2f57d95 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleCommon.java
@@ -107,11 +107,35 @@ public abstract class BattleCommon implements Battle
return burn;
}
- protected boolean abTurnDone()
+ protected boolean turnDoneForBoth()
{
return ((currentPlayer.getTurnDone() > 0) && (currentPlayer.getTurnDone() == getOpponent().getTurnDone()));
}
+ protected Player getWinner(int minTurns)
+ {
+ if (!turnDoneForBoth())
+ return null;
+
+ if (gePlayer.unitsLeft() == 0)
+ return usPlayer;
+ if (usPlayer.unitsLeft() == 0)
+ return gePlayer;
+
+ if (gePlayer.getTurnDone() <= minTurns)
+ return null;
+
+ usPlayer.objectivesWon = map.objectivesCount(Army.US);
+ gePlayer.objectivesWon = map.objectivesCount(Army.GE);
+
+ if (usPlayer.objectivesWon > gePlayer.objectivesWon)
+ return usPlayer;
+ else if (usPlayer.objectivesWon < gePlayer.objectivesWon)
+ return gePlayer;
+
+ return null;
+ }
+
@Override
public boolean turnDone()
{
diff --git a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
index 26e9999..6daf61a 100644
--- a/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
+++ b/core/src/ch/asynk/rustanddust/game/battles/BattleTest.java
@@ -41,26 +41,7 @@ public class BattleTest extends BattleCommon
@Override
public Player getWinner()
{
- if (!abTurnDone())
- return null;
-
- if (gePlayer.unitsLeft() == 0)
- return usPlayer;
- if (usPlayer.unitsLeft() == 0)
- return gePlayer;
-
- if (gePlayer.getTurnDone() <= 4)
- return null;
-
- usPlayer.objectivesWon = map.objectivesCount(Army.US);
- gePlayer.objectivesWon = map.objectivesCount(Army.GE);
-
- if (usPlayer.objectivesWon > gePlayer.objectivesWon)
- return usPlayer;
- if (usPlayer.objectivesWon < gePlayer.objectivesWon)
- return gePlayer;
-
- return null;
+ return getWinner(4);
}
@Override