summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-06 15:54:22 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-06 15:54:22 +0100
commitda875af4669dc8dfb243941c7f739a265329e9dd (patch)
tree92d58d250a61a6641b124680db00dd0d8c22e749 /core
parentf6469f181af872ee8387453bac0e884abc276fb4 (diff)
downloadRustAndDust-da875af4669dc8dfb243941c7f739a265329e9dd.zip
RustAndDust-da875af4669dc8dfb243941c7f739a265329e9dd.tar.gz
Battle: boolean checkVictory(Ctrl) -> Player checkVictory(Ctrl)
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/game/Battle.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/Ctrl.java5
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/BattleHeadToHead.java39
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