summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2014-10-12 02:02:10 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2014-10-12 02:02:10 +0200
commit68c438103d11a3cb14e8fd45047a984ebd229b84 (patch)
tree631513b76976593986a76c802aabe0cfe147422c /core/src/ch/asynk/tankontank/game
parent667a0a29512c8fdf9acfe547f6155221f387b73e (diff)
downloadRustAndDust-68c438103d11a3cb14e8fd45047a984ebd229b84.zip
RustAndDust-68c438103d11a3cb14e8fd45047a984ebd229b84.tar.gz
add game/Player
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
-rw-r--r--core/src/ch/asynk/tankontank/game/Player.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/Player.java b/core/src/ch/asynk/tankontank/game/Player.java
new file mode 100644
index 0000000..85869f8
--- /dev/null
+++ b/core/src/ch/asynk/tankontank/game/Player.java
@@ -0,0 +1,112 @@
+package ch.asynk.tankontank.game;
+
+import java.util.ArrayList;
+import java.util.Random;
+
+import com.badlogic.gdx.utils.Disposable;
+
+import com.badlogic.gdx.graphics.g2d.Batch;
+import com.badlogic.gdx.graphics.g2d.TextureAtlas;
+import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
+
+// import com.badlogic.gdx.math.Vector2;
+// import com.badlogic.gdx.math.Vector3;
+
+import ch.asynk.tankontank.engine.Pawn;
+import ch.asynk.tankontank.engine.gfx.Image;
+import ch.asynk.tankontank.engine.gfx.Drawable;
+
+public class 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 ArrayList<Pawn> units;
+ private ArrayList<Pawn> losses;
+ private ArrayList<Pawn> reinforcement;
+ private int actionPoints;
+
+ public Player(Army army, TextureAtlas atlas, String name, int size)
+ {
+ this.army = army;
+ this.flag = new Image(atlas.findRegion(name));
+ this.units = new ArrayList<Pawn>(size);
+ this.losses = new ArrayList<Pawn>(size);
+ this.reinforcement = new ArrayList<Pawn>(size);
+ setActionPoints();
+ }
+
+ public String toString()
+ {
+ return "Player : " + army + " AP: " + actionPoints +
+ " units:" + units.size() + " losses:" + losses.size() + " reinforcement:" + reinforcement.size();
+ }
+
+ @Override
+ public void dispose()
+ {
+ flag.dispose();
+ }
+
+ public void addUnit(Pawn pawn)
+ {
+ units.add(pawn);
+ }
+
+ public Image getFlag()
+ {
+ return flag;
+ }
+
+ public boolean apExhausted()
+ {
+ return (actionPoints <= 0);
+ }
+
+ public void burnDownOneAp()
+ {
+ actionPoints -= 1;
+ if (actionPoints < 0) System.err.println("AP < 0, damn that's very wrong");
+ }
+
+ public void turnEnd()
+ {
+ }
+
+ public void turnStart()
+ {
+ for (Pawn pawn : units)
+ pawn.reset();
+ setActionPoints();
+ }
+
+ private void setActionPoints()
+ {
+ this.actionPoints = 2 + rand.nextInt(3);
+ }
+
+ public boolean isEnemy(Pawn pawn)
+ {
+ return ((Unit) pawn).isEnemy(army);
+ }
+
+ public void setPosition(float x, float y)
+ {
+ flag.setPosition(x, y);
+ }
+
+ @Override
+ public void draw(Batch batch)
+ {
+ flag.draw(batch);
+ }
+
+ @Override
+ public void drawDebug(ShapeRenderer debugShapes)
+ {
+ flag.drawDebug(debugShapes);
+ }
+}