summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/Map.java
blob: a7bfc59e7b0bded92a7c23cae214b36d26756d58 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package ch.asynk.tankontank.game;

import java.util.Vector;
import java.util.HashSet;

import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.GridPoint2;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

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

public abstract class Map extends Board
{
    private final Vector<GridPoint2> possibleMoves = new Vector<GridPoint2>(20);
    private final Vector<GridPoint2> possibleTargets = new Vector<GridPoint2>(10);
    private final HashSet<GridPoint2> possiblePaths = new HashSet<GridPoint2>(10);

    protected abstract void setup();

    public Map(GameFactory gameFactory, Board.Config cfg, Texture texture)
    {
        super(gameFactory, cfg, texture);
        setup();
    }

    protected Hex getHex(int col, int row)
    {
        return (Hex) getTile(col, row);
    }

    public boolean isInPossibleMoves(GridPoint2 hex)
    {
        return possibleMoves.contains(hex);
    }

    public boolean isInPossiblePaths(GridPoint2 hex)
    {
        return possiblePaths.contains(hex);
    }

    public boolean isInPossibleTargets(GridPoint2 hex)
    {
        return possibleTargets.contains(hex);
    }

    public void enablePossibleMoves(boolean enable)
    {
        for(GridPoint2 hex : possibleMoves)
            enableOverlayOn(hex, Hex.GREEN, enable);
    }

    public void enablePossibleTargets(boolean enable)
    {
        for(GridPoint2 hex : possibleTargets)
            enableOverlayOn(hex, Hex.RED, enable);
    }

    public void enablePossiblePaths(boolean enable, boolean keepDots)
    {
        if (keepDots) {
            for(GridPoint2 hex : possiblePaths)
                enableOverlayOn(hex, Hex.GREEN, enable);
        } else {
            for(GridPoint2 hex : possiblePaths) {
                enableOverlayOn(hex, Hex.GREEN, enable);
                enableOverlayOn(hex, Hex.DOT, false);
            }
        }
    }

    public void showPossibleActions(Pawn pawn, GridPoint2 hex, boolean enable)
    {
        enablePossibleMoves(false);
        enablePossibleTargets(false);
        if (enable) {
            possibleMovesFrom(pawn, hex, possibleMoves);
            enablePossibleMoves(true);
            possibleTargetsFrom(pawn, hex, possibleTargets);
            enablePossibleTargets(true);
        }

    }

    public int possiblePathsSize()
    {
        return possiblePaths.size();
    }

    public int buildPossiblePaths(Pawn pawn, GridPoint2 from, GridPoint2 to)
    {
        return possiblePaths(pawn, from, to, possiblePaths);
    }

    public int possiblePathsPointToggle(GridPoint2 point)
    {
        return possiblePathsFilterToggle(point.x, point.y, possiblePaths);
    }

    public void clearPossibles()
    {
        enablePossibleMoves(false);
        enablePossiblePaths(false, false);
        enablePossibleTargets(false);
        clearNodesSet(possiblePaths);
        // clearNodesVector(possibleMoves);
        // clearNodesVector(possibleTargets);
    }

    public void toggleDotOverlay(GridPoint2 hex)
    {
        boolean enable= !isOverlayEnabledOn(hex.x, hex.y, Hex.DOT);
        enableOverlayOn(hex, Hex.DOT, enable);
    }

    public void enableFinalPath(GridPoint2 dst, boolean enable)
    {
        for(GridPoint2 hex : possiblePaths) {
            enableOverlayOn(hex, Hex.GREEN, false);
            enableOverlayOn(hex, Hex.DOT, false);
            enableOverlayOn(hex, Hex.MOVE, enable);
        }
        enableOverlayOn(dst, Hex.ROSE, true);
    }
}