summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-11-17 15:50:16 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2014-11-17 15:50:16 +0100
commit2c83bb0883c70ab0fff1b20cf6dedc3407e220e3 (patch)
treef9f0a849a5fc15531056ba9659562fb9581a82bc /core
parent793af2956fc0daa67585cae95489075788f72713 (diff)
downloadRustAndDust-2c83bb0883c70ab0fff1b20cf6dedc3407e220e3.zip
RustAndDust-2c83bb0883c70ab0fff1b20cf6dedc3407e220e3.tar.gz
game.Player swallows engine.Player -> use List<Unit> intead of List<Pawn>
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Player.java90
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java105
2 files changed, 91 insertions, 104 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Player.java b/core/src/ch/asynk/tankontank/engine/Player.java
deleted file mode 100644
index 8bda179..0000000
--- a/core/src/ch/asynk/tankontank/engine/Player.java
+++ /dev/null
@@ -1,90 +0,0 @@
-package ch.asynk.tankontank.engine;
-
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Random;
-import java.util.Iterator;
-
-import ch.asynk.tankontank.engine.Pawn;
-
-public abstract class Player
-{
- public Faction faction;
- public ArrayList<Pawn> units;
- public ArrayList<Pawn> casualties;
- public ArrayList<Pawn> reinforcement;
-
- public abstract void turnEnd();
- public abstract void turnStart();
-
- public Player(Faction faction, int n)
- {
- this.faction = faction;
- this.units = new ArrayList<Pawn>(n);
- this.casualties = new ArrayList<Pawn>(n);
- this.reinforcement = new ArrayList<Pawn>(n);
- }
-
- public String getName()
- {
- return faction.toString();
- }
-
- public boolean is(Faction faction)
- {
- return (this.faction == faction);
- }
-
- public boolean isEnemy(Pawn pawn)
- {
- return pawn.isEnemy(faction);
- }
-
- public boolean isEnemy(Faction other)
- {
- return faction.isEnemy(other);
- }
-
- public int unitsLeft()
- {
- return (units.size() + reinforcement.size());
- }
-
- public int reinforcement()
- {
- return reinforcement.size();
- }
-
- public int casualties()
- {
- return casualties.size();
- }
-
- public void addUnit(Pawn pawn)
- {
- units.add(pawn);
- }
-
- public void addReinforcement(Pawn pawn)
- {
- reinforcement.add(pawn);
- }
-
- public void unitEntry(Pawn pawn)
- {
- reinforcement.remove(pawn);
- units.add(pawn);
- }
-
- public void revertUnitEntry(Pawn pawn)
- {
- units.remove(pawn);
- reinforcement.add(pawn);
- }
-
- public void casualty(Pawn pawn)
- {
- units.remove(pawn);
- casualties.add(pawn);
- }
-}
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;