blob: 6bf9893fdaff2c39aef5d50a03f426bacdbb9c76 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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();
}
}
|