aboutsummaryrefslogtreecommitdiff
path: root/src/ch/epfl/xblast/PlayerID.java
blob: 72a48b9a9e0a1b4caa911ff9c096c59a4e0a4b77 (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
package ch.epfl.xblast;

/**
 * IDs the 4 different players.
 *
 * @author Pacien TRAN-GIRARD (261948)
 * @author Timothée FLOURE (257420)
 */
public enum PlayerID {

    PLAYER_1,
    PLAYER_2,
    PLAYER_3,
    PLAYER_4;

    public Cell initialPosition() {
        switch (this) {
            case PLAYER_1:
                return new Cell(1, 1);
            case PLAYER_2:
                return new Cell(13, 1);
            case PLAYER_3:
                return new Cell(13, 11);
            case PLAYER_4:
                return new Cell(1, 11);
            default:
                return null;
        }
    }

    public static PlayerID fromByte(byte b) {
        if ((int) b < 0 || (int) b >= PlayerAction.values().length)
            throw new IllegalArgumentException();

        return PlayerID.values()[(int) b];
    }

    public byte toByte() {
        return (byte) this.ordinal();
    }

}