blob: 6ce12bad694d406ff9eae83a0824a65aaf4a76ca (
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
|
package ch.epfl.xblast;
import java.util.Optional;
/**
* The player action enum.
*
* @author Timothée FLOURE (257420)
* @author Pacien TRAN-GIRARD (261948)
*/
public enum PlayerAction {
JOIN_GAME,
MOVE_N,
MOVE_E,
MOVE_S,
MOVE_W,
STOP,
DROP_BOMB;
public static PlayerAction fromByte(byte b) {
if ((int) b < 0 || (int) b >= PlayerAction.values().length)
throw new IllegalArgumentException();
return PlayerAction.values()[(int) b];
}
public byte toByte() {
return (byte) this.ordinal();
}
public Optional<Direction> associatedSpeedChangeEvent() {
switch (this) {
case MOVE_N:
return Optional.of(Direction.N);
case MOVE_E:
return Optional.of(Direction.E);
case MOVE_S:
return Optional.of(Direction.S);
case MOVE_W:
return Optional.of(Direction.W);
case STOP:
return Optional.empty();
default:
return null;
}
}
}
|