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

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 int unitsLeft()
    {
        return (units.size() + reinforcement.size());
    }

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

    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 casualty(Pawn pawn)
    {
        units.remove(pawn);
        casualties.add(pawn);
        System.err.println("    casualty : " + pawn);
    }

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

    public Iterator<Pawn> casualtiesIterator()
    {
        return casualties.iterator();
    }

    public Iterator<Pawn> reinforcementIterator()
    {
        return reinforcement.iterator();
    }
}