summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/GameStatePath.java
blob: fdb407d53fe6814eb1336c43b0dd589aa9734dc5 (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
package ch.asynk.tankontank.game;

import com.badlogic.gdx.math.GridPoint2;

public class GameStatePath extends GameStateCommon
{
    private GridPoint2 from = new GridPoint2(-1, -1);
    private GridPoint2 to = new GridPoint2(-1, -1);

    @Override
    public void touchDown()
    {
    }

    @Override
    public void touchUp()
    {
        int s = map.possiblePathsSize();
        if (s == 0) {
            s = buildPaths();
        } else {
            if (map.isInPossiblePaths(downHex))
                s = togglePoint();
            else
                s = reset();
        }

        // FIXME maybe there's more than one path left,
        // but that's irrelevant, ie 1 hex far
        if (s == 1) {
            unselectHex();
            hex.set(to.x, to.y);
            map.enableFinalPath(to, true);
            ctrl.setState(State.DIRECTION, false);
        }
    }

    private int buildPaths()
    {
        from.set(hex.x, hex.y);
        to.set(downHex.x, downHex.y);
        int s = map.buildPossiblePaths(pawn, from, to);
        map.enablePossibleMoves(false);
        map.toggleDotOverlay(downHex);
        map.enablePossiblePaths(true, true);
        return s;
    }

    private int togglePoint()
    {
        int s = 0;
        if ((downHex.x == from.x) && (downHex.y == from.y)) {
            s = map.possiblePathsSize();
        } else if ((downHex.x == to.x) && (downHex.y == to.y)) {
            s = reset();
        } else {
            map.enablePossiblePaths(false, true);
            map.toggleDotOverlay(downHex);
            s = map.possiblePathsPointToggle(downHex);
            map.enablePossiblePaths(true, true);
        }
        return s;
    }

    private int reset()
    {
        to.set(-1, -1);
        from.set(-1, -1);
        map.hidePaths();
        map.resetPaths();
        ctrl.setState(State.NONE, false);
        return -1;
    }
}