From 7e4e99ae6cbd1df3acd94febad7d01122bcb8cc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Sun, 24 Jan 2016 11:12:05 +0100 Subject: BattleCommon: add getWinner(int) --- .../asynk/rustanddust/game/battles/Battle00.java | 20 +---------------- .../rustanddust/game/battles/BattleCommon.java | 26 +++++++++++++++++++++- .../asynk/rustanddust/game/battles/BattleTest.java | 21 +---------------- 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 -- cgit v1.1-2-g2b99