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

import ch.asynk.tankontank.game.Map;

public class GameCtrl
{
    private GameState noneState = new GameStateNone();
    private GameState pathState = new GameStatePath();
    private GameState directionState = new GameStateDirection();

    private GameState state;

    public GameCtrl(Map map)
    {
        this.noneState = new GameStateNone(this, map);
        this.pathState = new GameStatePath();
        this.directionState = new GameStateDirection();

        this.state = noneState;
    }

    public void setState(GameState.State state, boolean forward)
    {
        switch(state) {
            case NONE:
                this.state = noneState;
                break;
            case PATH:
                this.state = pathState;
                break;
            case DIRECTION:
                this.state = directionState;
                break;
            default:
                break;
        }

        if (forward)
            this.state.touchDown();
    }

    public void touchDown(float x, float y)
    {
        if (GameStateCommon.down(x, y))
            state.touchDown();
    }

    public void touchUp(float x, float y)
    {
        if (GameStateCommon.up(x, y))
            state.touchUp();
    }
}