summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-17 14:52:51 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-17 14:52:51 +0100
commit8d6f8738203d45d4da116e390b6e6685f4636bb3 (patch)
treecc78b335fcbf9f805f419d9f7aa33284b3c3b815
parentb4c82404bcb7b2e1f58339088ccf48023c1da6f9 (diff)
downloadRustAndDust-8d6f8738203d45d4da116e390b6e6685f4636bb3.zip
RustAndDust-8d6f8738203d45d4da116e390b6e6685f4636bb3.tar.gz
Player: clean up API
-rw-r--r--core/src/ch/asynk/tankontank/engine/Board.java11
-rw-r--r--core/src/ch/asynk/tankontank/engine/Player.java46
-rw-r--r--core/src/ch/asynk/tankontank/game/Map.java6
-rw-r--r--core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java2
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/hud/UnitDock.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateEngage.java4
-rw-r--r--core/src/ch/asynk/tankontank/game/states/StateSelect.java4
8 files changed, 35 insertions, 46 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Board.java b/core/src/ch/asynk/tankontank/engine/Board.java
index 203436c..a7ebabf 100644
--- a/core/src/ch/asynk/tankontank/engine/Board.java
+++ b/core/src/ch/asynk/tankontank/engine/Board.java
@@ -1,5 +1,6 @@
package ch.asynk.tankontank.engine;
+import java.util.List;
import java.util.Iterator;
import java.util.Collection;
import java.util.ArrayList;
@@ -302,11 +303,10 @@ public abstract class Board implements Disposable
return searchBoard.possibleTargetsFrom(pawn, targets);
}
- protected int collectPossibleTargets(Pawn pawn, Iterator<Pawn> units, PawnCollection targets)
+ protected int collectPossibleTargets(Pawn pawn, List<Pawn> units, PawnCollection targets)
{
targets.clear();
- while (units.hasNext()) {
- Pawn target = units.next();
+ for (Pawn target : units) {
if (pawn.canEngage(target) && searchBoard.collectAttacks(pawn, target, true))
targets.add(target);
}
@@ -332,11 +332,10 @@ public abstract class Board implements Disposable
return assists.size();
}
- protected int collectAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units, PawnCollection assists)
+ protected int collectAttackAssists(Pawn pawn, Pawn target, List<Pawn> units, PawnCollection assists)
{
assists.clear();
- while (units.hasNext()) {
- Pawn p = units.next();
+ for (Pawn p : units) {
if ((p != pawn) && p.canEngage(target) && searchBoard.collectAttacks(p, target, !p.canAssistEngagementWithoutLos()))
assists.add(p);
}
diff --git a/core/src/ch/asynk/tankontank/engine/Player.java b/core/src/ch/asynk/tankontank/engine/Player.java
index cb9543d..8bda179 100644
--- a/core/src/ch/asynk/tankontank/engine/Player.java
+++ b/core/src/ch/asynk/tankontank/engine/Player.java
@@ -9,10 +9,10 @@ import ch.asynk.tankontank.engine.Pawn;
public abstract class Player
{
- protected Faction faction;
- protected ArrayList<Pawn> units;
- protected ArrayList<Pawn> casualties;
- protected ArrayList<Pawn> reinforcement;
+ public Faction faction;
+ public ArrayList<Pawn> units;
+ public ArrayList<Pawn> casualties;
+ public ArrayList<Pawn> reinforcement;
public abstract void turnEnd();
public abstract void turnStart();
@@ -25,44 +25,39 @@ public abstract class Player
this.reinforcement = new ArrayList<Pawn>(n);
}
- public Faction getFaction()
- {
- return faction;
- }
-
- public List<Pawn> getReinforcement()
+ public String getName()
{
- return reinforcement;
+ return faction.toString();
}
- public int unitsLeft()
+ public boolean is(Faction faction)
{
- return (units.size() + reinforcement.size());
+ return (this.faction == faction);
}
- public int casualties()
+ public boolean isEnemy(Pawn pawn)
{
- return casualties.size();
+ return pawn.isEnemy(faction);
}
- public String getName()
+ public boolean isEnemy(Faction other)
{
- return faction.toString();
+ return faction.isEnemy(other);
}
- public boolean is(Faction faction)
+ public int unitsLeft()
{
- return (this.faction == faction);
+ return (units.size() + reinforcement.size());
}
- public boolean isEnemy(Pawn pawn)
+ public int reinforcement()
{
- return pawn.isEnemy(faction);
+ return reinforcement.size();
}
- public boolean isEnemy(Faction other)
+ public int casualties()
{
- return faction.isEnemy(other);
+ return casualties.size();
}
public void addUnit(Pawn pawn)
@@ -92,9 +87,4 @@ public abstract class Player
units.remove(pawn);
casualties.add(pawn);
}
-
- public Iterator<Pawn> unitIterator()
- {
- return units.iterator();
- }
}
diff --git a/core/src/ch/asynk/tankontank/game/Map.java b/core/src/ch/asynk/tankontank/game/Map.java
index 168d07d..f405845 100644
--- a/core/src/ch/asynk/tankontank/game/Map.java
+++ b/core/src/ch/asynk/tankontank/game/Map.java
@@ -1,6 +1,6 @@
package ch.asynk.tankontank.game;
-import java.util.Iterator;
+import java.util.List;
import java.util.Random;
import com.badlogic.gdx.audio.Sound;
@@ -118,7 +118,7 @@ public abstract class Map extends Board
return possiblePaths.toggleCtrlTile(hex);
}
- public int collectPossibleTargets(Pawn pawn, Iterator<Pawn> foes)
+ public int collectPossibleTargets(Pawn pawn, List<Pawn> foes)
{
if (!pawn.canEngage()) {
possibleTargets.clear();
@@ -140,7 +140,7 @@ public abstract class Map extends Board
return moveablePawns.size();
}
- public int collectAttackAssists(Pawn pawn, Pawn target, Iterator<Pawn> units)
+ public int collectAttackAssists(Pawn pawn, Pawn target, List<Pawn> units)
{
int s = collectAttackAssists(pawn, target, units, engagementAssists);
activatedPawns.add(pawn);
diff --git a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
index f31aff4..4571772 100644
--- a/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
+++ b/core/src/ch/asynk/tankontank/game/battles/BattleFrontalAssault.java
@@ -47,7 +47,7 @@ public class BattleFrontalAssault extends BattleCommon
@Override
public boolean deploymentDone(Player player)
{
- int n = player.getReinforcement().size();
+ int n = player.reinforcement();
if (n == 0) {
player.deploymentDone();
return true;
diff --git a/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java b/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java
index 5cd4b5f..4ac8c88 100644
--- a/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java
+++ b/core/src/ch/asynk/tankontank/game/hud/PlayerInfo.java
@@ -95,7 +95,7 @@ public class PlayerInfo implements Disposable, Drawable
unitDock.hide();
turns.write("" + player.getTurn());
aps.write("" + player.getAp());
- int r = player.getReinforcement().size();
+ int r = player.reinforcement();
if (r == 0) {
reinforcement.visible = false;
} else {
@@ -103,7 +103,7 @@ public class PlayerInfo implements Disposable, Drawable
reinforcement.write("" + r);
}
- if (player.getFaction() == Army.GE)
+ if (player.is(Army.GE))
flag = geFlag;
else
flag = usFlag;
diff --git a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
index 0e67630..ce2ac04 100644
--- a/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
+++ b/core/src/ch/asynk/tankontank/game/hud/UnitDock.java
@@ -96,9 +96,9 @@ public class UnitDock extends Bg
{
float x = position.getX(rect.width * SCALE);
if (done) {
- pawns = ctrl.player.getReinforcement();
- if(pawns.size() == 0)
+ if(ctrl.player.reinforcement() == 0)
return;
+ pawns = ctrl.player.reinforcement;
rect.width = pawns.get(0).getWidth() + (2 * padding);
rect.height = ((pawns.get(0).getHeight() * pawns.size()) + ((pawns.size() + 1) * padding));
rect.x = (position.isLeft() ? (0 - (rect.width * SCALE)) : (x + (rect.width * SCALE)));
diff --git a/core/src/ch/asynk/tankontank/game/states/StateEngage.java b/core/src/ch/asynk/tankontank/game/states/StateEngage.java
index 1586d80..4b1539b 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateEngage.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateEngage.java
@@ -19,7 +19,7 @@ public class StateEngage extends StateCommon
activeUnit = null;
// use selectedHex and selectedUnit
map.hidePossibleTargets();
- map.collectPossibleTargets(selectedUnit, ctrl.opponent.unitIterator());
+ map.collectPossibleTargets(selectedUnit, ctrl.opponent.units);
map.showPossibleTargets();
if (to != null) {
// quick fire -> replay touchUp
@@ -89,7 +89,7 @@ public class StateEngage extends StateCommon
to = upHex;
activeUnit = unit;
activeUnit.showTarget();
- map.collectAttackAssists(selectedUnit, activeUnit, ctrl.player.unitIterator());
+ map.collectAttackAssists(selectedUnit, activeUnit, ctrl.player.units);
map.showAttackAssists();
ctrl.hud.actionButtons.show(Buttons.ENGAGE.b | Buttons.DONE.b | ((ctrl.cfg.canCancel) ? Buttons.ABORT.b : 0));
}
diff --git a/core/src/ch/asynk/tankontank/game/states/StateSelect.java b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
index 7e7059e..7bdc815 100644
--- a/core/src/ch/asynk/tankontank/game/states/StateSelect.java
+++ b/core/src/ch/asynk/tankontank/game/states/StateSelect.java
@@ -77,9 +77,9 @@ public class StateSelect extends StateCommon
int moves = map.collectPossibleMoves(selectedUnit);
int targets = 0;
if (isEnemy)
- targets = map.collectPossibleTargets(selectedUnit, ctrl.player.unitIterator());
+ targets = map.collectPossibleTargets(selectedUnit, ctrl.player.units);
else
- targets = map.collectPossibleTargets(selectedUnit, ctrl.opponent.unitIterator());
+ targets = map.collectPossibleTargets(selectedUnit, ctrl.opponent.units);
if (moves > 0)
map.collectMoveablePawns(selectedUnit);
showPossibilities(selectedUnit);