summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java105
1 files changed, 91 insertions, 14 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
index ca0977b..636fdd5 100644
--- a/core/src/ch/asynk/tankontank/game/Player.java
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -1,11 +1,13 @@
package ch.asynk.tankontank.game;
import java.util.Random;
+import java.util.List;
+import java.util.ArrayList;
import ch.asynk.tankontank.TankOnTank;
import ch.asynk.tankontank.engine.Pawn;
-public class Player extends ch.asynk.tankontank.engine.Player
+public class Player
{
private static final float MOVE_TIME = 0.4f;
@@ -15,14 +17,22 @@ public class Player extends ch.asynk.tankontank.engine.Player
private int apSpent;
private int actionPoints;
private boolean deploymentDone;
- // stats
+
+ public Army army;
+ public ArrayList<Unit> units;
+ public ArrayList<Unit> casualties;
+ public ArrayList<Unit> reinforcement;
+
public int actionCount;
public int lostEngagementCount;
public int wonEngagementCount;
public Player(final TankOnTank game, Army army, int n)
{
- super(army, n);
+ this.army = army;
+ this.units = new ArrayList<Unit>(n);
+ this.casualties = new ArrayList<Unit>(n);
+ this.reinforcement = new ArrayList<Unit>(n);
this.turn = 0;
this.apSpent = 0;
this.actionPoints = 0;
@@ -32,9 +42,14 @@ public class Player extends ch.asynk.tankontank.engine.Player
this.wonEngagementCount = 0;
}
+ public String getName()
+ {
+ return army.toString();
+ }
+
public String toString()
{
- return faction + " AP: " + actionPoints +
+ return army + " AP: " + actionPoints +
" units:" + units.size() + " casualties:" + casualties.size();
}
@@ -43,6 +58,70 @@ public class Player extends ch.asynk.tankontank.engine.Player
return String.format("%s\n%4d\n%4d\n%4d\n%4d\n%4d", getName(), actionCount, unitsLeft(), casualties.size(), wonEngagementCount, lostEngagementCount);
}
+ public boolean is(Army army)
+ {
+ return (this.army == army);
+ }
+
+ public boolean isEnemy(Unit unit)
+ {
+ return unit.isEnemy(army);
+ }
+
+ public boolean isEnemy(Army other)
+ {
+ return army.isEnemy(other);
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<Pawn> unitsAsPawns()
+ {
+ return (List) units;
+ }
+
+ public int unitsLeft()
+ {
+ return (units.size() + reinforcement.size());
+ }
+
+ public int reinforcement()
+ {
+ return reinforcement.size();
+ }
+
+ public int casualties()
+ {
+ return casualties.size();
+ }
+
+ public void addUnit(Unit unit)
+ {
+ units.add(unit);
+ }
+
+ public void addReinforcement(Unit unit)
+ {
+ reinforcement.add(unit);
+ }
+
+ public void unitEntry(Unit unit)
+ {
+ reinforcement.remove(unit);
+ units.add(unit);
+ }
+
+ public void revertUnitEntry(Unit unit)
+ {
+ units.remove(unit);
+ reinforcement.add(unit);
+ }
+
+ public void casualty(Unit unit)
+ {
+ units.remove(unit);
+ casualties.add(unit);
+ }
+
public int getAp()
{
return ((apSpent < actionPoints) ? (apSpent + 1) : apSpent);
@@ -75,19 +154,17 @@ public class Player extends ch.asynk.tankontank.engine.Player
if (apSpent > actionPoints) TankOnTank.debug("ERROR: spent too much AP, please report");
}
- @Override
public void turnEnd()
{
}
- @Override
public void turnStart()
{
if (!deploymentDone)
return;
turn += 1;
- for (Pawn pawn : units)
- pawn.reset();
+ for (Unit unit : units)
+ unit.reset();
computeActionPoints();
}
@@ -107,23 +184,23 @@ public class Player extends ch.asynk.tankontank.engine.Player
apSpent = 0;
}
- public boolean canPromote(Pawn pawn)
+ public boolean canPromote(Unit unit)
{
- if (pawn.isHq()) return false;
- for (Pawn p: casualties)
- if (p.isHqOf(pawn)) return true;
+ if (unit.isHq()) return false;
+ for (Unit p: casualties)
+ if (p.isHqOf(unit)) return true;
return false;
}
public Unit promote(Unit unit)
{
- for (Pawn p: casualties) {
+ for (Unit p: casualties) {
if (p.isHqOf(unit)) {
units.remove(unit);
casualties.add(unit);
units.add(p);
casualties.remove(p);
- return (Unit) p;
+ return p;
}
}
return null;