summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-17 16:33:26 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-17 16:33:26 +0200
commit70f26f0bd227ec9871447d9582b4f7cb78f01a4b (patch)
tree4f8ea37ae9e070c4e6c5b72441fce12f96704c9b /core/src/ch/asynk/tankontank
parent4af430e68750e56cc62ddba117f48ef9aff65619 (diff)
downloadRustAndDust-70f26f0bd227ec9871447d9582b4f7cb78f01a4b.zip
RustAndDust-70f26f0bd227ec9871447d9582b4f7cb78f01a4b.tar.gz
Player: -> engine/Player and game/Player
Diffstat (limited to 'core/src/ch/asynk/tankontank')
-rw-r--r--core/src/ch/asynk/tankontank/engine/Player.java68
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java50
2 files changed, 76 insertions, 42 deletions
diff --git a/core/src/ch/asynk/tankontank/engine/Player.java b/core/src/ch/asynk/tankontank/engine/Player.java
new file mode 100644
index 0000000..c1c9365
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/engine/Player.java
@@ -0,0 +1,68 @@
+package ch.asynk.tankontank.engine;
+
+import java.util.ArrayList;
+import java.util.Random;
+import java.util.Iterator;
+
+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 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 isEnemy(Pawn pawn)
+ {
+ return pawn.isEnemy(faction);
+ }
+
+ public void addUnit(Pawn pawn)
+ {
+ units.add(pawn);
+ }
+
+ public void addReinforcement(Pawn pawn)
+ {
+ reinforcement.add(pawn);
+ }
+
+ public void casualty(Pawn pawn)
+ {
+ units.remove(pawn);
+ casualties.add(pawn);
+ System.err.println(" casualty : " + pawn);
+ }
+
+ public Iterator<Pawn> unitIterator()
+ {
+ return units.iterator();
+ }
+
+ public Iterator<Pawn> casualtiesIterator()
+ {
+ return casualties.iterator();
+ }
+
+ public Iterator<Pawn> reinforcementIterator()
+ {
+ return reinforcement.iterator();
+ }
+}
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
index 15efea0..ee10dea 100644
--- a/core/src/ch/asynk/tankontank/game/Player.java
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -1,8 +1,6 @@
package ch.asynk.tankontank.game;
-import java.util.ArrayList;
import java.util.Random;
-import java.util.Iterator;
import com.badlogic.gdx.utils.Disposable;
@@ -17,42 +15,30 @@ import ch.asynk.tankontank.engine.gfx.Image;
import ch.asynk.tankontank.engine.gfx.Drawable;
import ch.asynk.tankontank.game.hud.Msg;
-public class Player implements Drawable, Disposable
+public class Player extends ch.asynk.tankontank.engine.Player implements Drawable, Disposable
{
private static final float MOVE_TIME = 0.4f;
private static Random rand = new Random();
- private Army army;
- private Image flag;
- private Msg status;
private int turn;
private int apSpent;
private int actionPoints;
- private ArrayList<Pawn> units;
- private ArrayList<Pawn> casualties;
- private ArrayList<Pawn> reinforcement;
+ private Image flag;
+ private Msg status;
- public Player(final TankOnTank game, Army army, BitmapFont font, TextureAtlas atlas, String name, int size)
+ public Player(final TankOnTank game, Army army, BitmapFont font, TextureAtlas atlas, String name, int n)
{
- this.army = army;
+ super(army, n);
this.turn = 0;
this.actionPoints = 0;
this.flag = new Image(atlas.findRegion(name));
- this.units = new ArrayList<Pawn>(size);
- this.casualties = new ArrayList<Pawn>(size);
- this.reinforcement = new ArrayList<Pawn>(size);
this.status = new Msg(font, atlas.findRegion("disabled"));
}
- public String getName()
- {
- return army.toString();
- }
-
public String toString()
{
- return army + " AP: " + actionPoints +
+ return faction + " AP: " + actionPoints +
" units:" + units.size() + " casualties:" + casualties.size() + " reinforcement:" + reinforcement.size();
}
@@ -62,18 +48,6 @@ public class Player implements Drawable, Disposable
flag.dispose();
}
- public void addUnit(Pawn pawn)
- {
- units.add(pawn);
- }
-
- public void casualty(Pawn pawn)
- {
- units.remove(pawn);
- casualties.add(pawn);
- System.err.println(" casualty : " + pawn);
- }
-
public boolean apExhausted()
{
return (apSpent == actionPoints);
@@ -86,10 +60,12 @@ public class Player implements Drawable, Disposable
if (apSpent > actionPoints) System.err.println("ERROR: spent too much AP, please report");
}
+ @Override
public void turnEnd()
{
}
+ @Override
public void turnStart()
{
turn += 1;
@@ -120,11 +96,6 @@ public class Player implements Drawable, Disposable
status.write("Turn: " + turn + " AP: " + (apSpent + 1), flag.getX(), (flag.getY() - 40), 0, 10);
}
- public boolean isEnemy(Pawn pawn)
- {
- return pawn.isEnemy(army);
- }
-
public boolean canPromote(Pawn pawn)
{
if (pawn.isHq()) return false;
@@ -157,11 +128,6 @@ public class Player implements Drawable, Disposable
flag.setPosition(x, (y - flag.getHeight()));
}
- public Iterator<Pawn> unitIterator()
- {
- return units.iterator();
- }
-
@Override
public void draw(Batch batch)
{