diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Battle.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Ctrl.java | 5 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java | 39 |
3 files changed, 27 insertions, 19 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Battle.java b/core/src/ch/asynk/tankontank/game/Battle.java index ec60ffc..5112355 100644 --- a/core/src/ch/asynk/tankontank/game/Battle.java +++ b/core/src/ch/asynk/tankontank/game/Battle.java @@ -19,7 +19,7 @@ public interface Battle public void setup(Map map, Player firstPlayer, Player secondPlayer); - public boolean checkVictory(Ctrl ctrl); + public Player checkVictory(Ctrl ctrl); public TileSet getEntryPoint(Unit unit); diff --git a/core/src/ch/asynk/tankontank/game/Ctrl.java b/core/src/ch/asynk/tankontank/game/Ctrl.java index 25e4e62..25a4f79 100644 --- a/core/src/ch/asynk/tankontank/game/Ctrl.java +++ b/core/src/ch/asynk/tankontank/game/Ctrl.java @@ -102,8 +102,9 @@ public class Ctrl implements Disposable private void nextPlayer() { player.turnEnd(); - if (battle.checkVictory(this)) { - TankOnTank.debug("TODO " + player + " has won !!!!!!!!!!!"); + Player winner = battle.checkVictory(this); + if (winner != null) { + TankOnTank.debug("TODO " + winner + " has won !!!!!!!!!!!"); } Player tmp = player; player = opponent; diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java index 42c01d2..167c53a 100644 --- a/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java +++ b/core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java @@ -6,10 +6,12 @@ import com.badlogic.gdx.math.GridPoint2; import ch.asynk.tankontank.game.Ctrl; import ch.asynk.tankontank.game.Map; +import ch.asynk.tankontank.game.Hex; import ch.asynk.tankontank.game.Army; import ch.asynk.tankontank.game.Player; import ch.asynk.tankontank.game.Unit; import ch.asynk.tankontank.game.Unit.UnitId; +import ch.asynk.tankontank.engine.Tile; import ch.asynk.tankontank.engine.TileSet; import ch.asynk.tankontank.engine.Orientation; @@ -21,28 +23,33 @@ public class BattleHeadToHead extends BattleCommon randomizeArmies(); } - public boolean checkVictory(Ctrl ctrl) + public Player checkVictory(Ctrl ctrl) { if (ctrl.opponent.unitsLeft() == 0) - return true; + return null; if ((ctrl.player.getTurn() < 10) || (ctrl.opponent.getTurn() < 10)) - return false; + return null; Unit unit; - int objectives = 0; - - unit = ctrl.map.getHex(7, 7).getUnit(); - if ((unit != null) && (!ctrl.player.isEnemy(unit))) - objectives += 1; - unit = ctrl.map.getHex(6, 4).getUnit(); - if ((unit != null) && (!ctrl.player.isEnemy(unit))) - objectives += 1; - unit = ctrl.map.getHex(6, 1).getUnit(); - if ((unit != null) && (!ctrl.player.isEnemy(unit))) - objectives += 1; - - return (objectives > 1); + int player = 0; + int opponent = 0; + + for (Tile tile : objectives) { + unit = ((Hex) tile).getUnit(); + if (unit != null) { + if (ctrl.player.isEnemy(unit)) + opponent += 1; + else + player += 1; + } + } + + if (player > 1) + return ctrl.player; + else if (opponent > 1) + return ctrl.opponent; + return null; } @Override |