summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/Hex.java
blob: 70377acef47c96509b729039fce585f6e26008f7 (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package ch.asynk.tankontank.game;

import java.util.Iterator;

import com.badlogic.gdx.graphics.g2d.TextureAtlas;

import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.Tile;
import ch.asynk.tankontank.engine.Board;
import ch.asynk.tankontank.engine.Orientation;

public class Hex extends Tile
{
    public enum Terrain
    {
        OFFMAP,
        BLOCKED,
        CLEAR,
        HILLS,
        WOODS,
        TOWN
    }

    public static final int FOG = 0;
    public static final int BLUE = 1;
    public static final int GREEN = 2;
    public static final int RED = 3;
    public static final int DOT = 4;
    public static final int MOVE = 5;
    public static final int ROSE = 6;

    public Terrain terrain;
    public int roads;

    public Hex(float x, float y, TextureAtlas atlas)
    {
        super(x, y, atlas);
        this.terrain = Terrain.CLEAR;
        this.roads = 0;
    }

    @Override
    public boolean isOffMap()
    {
        return terrain == Terrain.OFFMAP;
    }

    @Override
    public boolean blockLineOfSightFrom(Tile tile)
    {
        if ((terrain == Terrain.CLEAR) && !hasUnits())
            return false;

        if ((((Hex) tile).terrain == Terrain.HILLS) && (terrain == Terrain.CLEAR))
            return false;

        return true;
    }

    @Override
    public boolean atLeastOneMove(Pawn pawn)
    {
        if (hasUnits() || (terrain == Terrain.BLOCKED) || (terrain == Terrain.OFFMAP))
            return false;
        return true;
    }

    @Override
    public boolean road(Orientation side)
    {
        return (side.s == (roads & side.s));
    }

    @Override
    public int costFrom(Pawn pawn, Orientation side, boolean road)
    {
        if (hasUnits()) return Integer.MAX_VALUE;
        if (road) return 1;

        int c = 0;
        switch(terrain) {
            case CLEAR:
            case HILLS:
                c = 1;
                break;
            case WOODS:
            case TOWN:
                c = 2;
                break;
            case OFFMAP:
            case BLOCKED:
                c = Integer.MAX_VALUE;
                break;
        }

        return c;
    }

    @Override
    public boolean hasTargetsFor(Pawn pawn)
    {
        if (!hasUnits()) return false;

        Iterator<Pawn> itr = stack.iterator();
        while(itr.hasNext())
            if (itr.next().isEnemy(pawn)) return true;

        return false;
    }
}