diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-16 23:25:39 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2014-09-16 23:25:39 +0200 |
commit | e3285ab8a207734cf12db9dc85fcc3eabaa592fd (patch) | |
tree | 442e0785422abc6e43824983bb49af657edcaac8 /core/src/ch/asynk/tankontank/game | |
parent | c92d75e6065d1a4b23a8d4fd39303b24d62c5008 (diff) | |
download | RustAndDust-e3285ab8a207734cf12db9dc85fcc3eabaa592fd.zip RustAndDust-e3285ab8a207734cf12db9dc85fcc3eabaa592fd.tar.gz |
add game/MapHexp
Diffstat (limited to 'core/src/ch/asynk/tankontank/game')
-rw-r--r-- | core/src/ch/asynk/tankontank/game/MapHex.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/core/src/ch/asynk/tankontank/game/MapHex.java b/core/src/ch/asynk/tankontank/game/MapHex.java new file mode 100644 index 0000000..6bf9893 --- /dev/null +++ b/core/src/ch/asynk/tankontank/game/MapHex.java @@ -0,0 +1,69 @@ +package ch.asynk.tankontank.game; + +import java.util.ArrayDeque; + +public class MapHex implements Hex +{ + public enum Terrain + { + CLEAR, + HILLS, + WOODS, + TOWN + } + + public Terrain terrain; + public int roads; + private ArrayDeque<Pawn> stack; + + public MapHex(Terrain t) + { + this.terrain = t; + this.roads = 0; + this.stack = null; + } + + public MapHex(Terrain t, int roads) + { + this.terrain = t; + this.roads = roads; + this.stack = null; + } + + public int costFrom(Side side) + { + if (side.v == (roads & side.v)) return 1; + + int c = 0; + switch(terrain) { + case CLEAR: + case HILLS: + c = 1; + break; + case WOODS: + case TOWN: + c = 2; + break; + } + + return c; + } + + public int push(Pawn pawn) + { + if (stack == null) stack = new ArrayDeque<Pawn>(); + stack.push(pawn); + return stack.size(); + } + + public void remove(Pawn pawn) + { + stack.remove(pawn); + } + + public Pawn getTop() + { + if ((stack == null) || (stack.size() == 0)) return null; + return stack.getFirst(); + } +} |