diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/src/ch/asynk/tankontank/engine/Player.java | 68 | ||||
-rw-r--r-- | core/src/ch/asynk/tankontank/game/Player.java | 50 |
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) { |