summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/tankontank/game/Player.java
blob: adc2f059f81b0203b29b41f7d4104bc920830090 (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.ArrayList;
import java.util.Random;
import java.util.Iterator;

import com.badlogic.gdx.utils.Disposable;

import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;

import ch.asynk.tankontank.engine.Pawn;
import ch.asynk.tankontank.engine.gfx.Image;
import ch.asynk.tankontank.engine.gfx.Drawable;

public class Player implements Drawable, Disposable
{
    private static final float MOVE_TIME = 0.4f;

    private static Random rand = new Random();

    private Army army;
    private Image flag;
    private ArrayList<Pawn> units;
    private ArrayList<Pawn> losses;
    private ArrayList<Pawn> reinforcement;
    private int actionPoints;

    public Player(Army army, TextureAtlas atlas, String name, int size)
    {
        this.army = army;
        this.flag = new Image(atlas.findRegion(name));
        this.units = new ArrayList<Pawn>(size);
        this.losses = new ArrayList<Pawn>(size);
        this.reinforcement = new ArrayList<Pawn>(size);
        this.actionPoints = 0;
    }

    public String toString()
    {
        return army + " AP: " + actionPoints +
            " units:" + units.size() + " losses:" + losses.size() + " reinforcement:" + reinforcement.size();
    }

    @Override
    public void dispose()
    {
        flag.dispose();
    }

    public void addUnit(Pawn pawn)
    {
        units.add(pawn);
    }

    public Image getFlag()
    {
        return flag;
    }

    public boolean apExhausted()
    {
        return (actionPoints <= 0);
    }

    public void burnDownOneAp()
    {
        actionPoints -= 1;
        if (actionPoints < 0) System.err.println("AP < 0, damn that's very wrong");
    }

    public void turnEnd()
    {
        System.err.println("TurnEnd   " + toString());
    }

    public void turnStart()
    {
        for (Pawn pawn : units)
            pawn.reset();
        setActionPoints();
        System.err.println("TurnStart " + toString());
    }

    public int d6()
    {
        return rand.nextInt(6) + 1;
    }

    private void setActionPoints()
    {
        this.actionPoints = 2;
        if (d6() > 2) {
            this.actionPoints += 1;
            if (d6() > 3)
                this.actionPoints += 1;
        }
    }

    public boolean isEnemy(Pawn pawn)
    {
        return ((Unit) pawn).isEnemy(army);
    }

    public void setPosition(float x, float y)
    {
        flag.setPosition(x, y);
    }

    public Iterator<Pawn> unitIterator()
    {
        return units.iterator();
    }

    @Override
    public void draw(Batch batch)
    {
        flag.draw(batch);
    }

    @Override
    public void drawDebug(ShapeRenderer debugShapes)
    {
        flag.drawDebug(debugShapes);
    }
}