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

import java.util.List;
import java.util.ArrayList;
import java.util.Random;
import java.util.Iterator;

import ch.asynk.tankontank.engine.Pawn;

public abstract class Player
{
    protected Faction faction;
    protected ArrayList<Pawn> units;
    protected ArrayList<Pawn> casualties;
    protected ArrayList<Pawn> reinforcement;

    public abstract void turnEnd();
    public abstract void turnStart();

    public Player(Faction faction, int n)
    {
        this.faction = faction;
        this.units = new ArrayList<Pawn>(n);
        this.casualties = new ArrayList<Pawn>(n);
        this.reinforcement = new ArrayList<Pawn>(n);
    }

    public Faction getFaction()
    {
        return faction;
    }

    public List<Pawn> getReinforcement()
    {
        return reinforcement;
    }

    public int unitsLeft()
    {
        return (units.size() + reinforcement.size());
    }

    public int casualties()
    {
        return casualties.size();
    }

    public String getName()
    {
        return faction.toString();
    }

    public boolean is(Faction faction)
    {
        return (this.faction == faction);
    }

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

    public boolean isEnemy(Faction other)
    {
        return faction.isEnemy(other);
    }

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

    public void addReinforcement(Pawn pawn)
    {
        reinforcement.add(pawn);
    }

    public void unitEntry(Pawn pawn)
    {
        reinforcement.remove(pawn);
        units.add(pawn);
    }

    public void revertUnitEntry(Pawn pawn)
    {
        units.remove(pawn);
        reinforcement.add(pawn);
    }

    public void casualty(Pawn pawn)
    {
        units.remove(pawn);
        casualties.add(pawn);
    }

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