diff options
Diffstat (limited to 'core/src/ch')
-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(); + } +} |