diff options
Diffstat (limited to 'src/ch/epfl/xblast/PlayerAction.java')
-rw-r--r-- | src/ch/epfl/xblast/PlayerAction.java | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/ch/epfl/xblast/PlayerAction.java b/src/ch/epfl/xblast/PlayerAction.java index 703bc9d..6ce12ba 100644 --- a/src/ch/epfl/xblast/PlayerAction.java +++ b/src/ch/epfl/xblast/PlayerAction.java | |||
@@ -1,5 +1,7 @@ | |||
1 | package ch.epfl.xblast; | 1 | package ch.epfl.xblast; |
2 | 2 | ||
3 | import java.util.Optional; | ||
4 | |||
3 | /** | 5 | /** |
4 | * The player action enum. | 6 | * The player action enum. |
5 | * | 7 | * |
@@ -14,6 +16,34 @@ public enum PlayerAction { | |||
14 | MOVE_S, | 16 | MOVE_S, |
15 | MOVE_W, | 17 | MOVE_W, |
16 | STOP, | 18 | STOP, |
17 | DROP_BOMB | 19 | DROP_BOMB; |
20 | |||
21 | public static PlayerAction fromByte(byte b) { | ||
22 | if ((int) b < 0 || (int) b >= PlayerAction.values().length) | ||
23 | throw new IllegalArgumentException(); | ||
24 | |||
25 | return PlayerAction.values()[(int) b]; | ||
26 | } | ||
27 | |||
28 | public byte toByte() { | ||
29 | return (byte) this.ordinal(); | ||
30 | } | ||
31 | |||
32 | public Optional<Direction> associatedSpeedChangeEvent() { | ||
33 | switch (this) { | ||
34 | case MOVE_N: | ||
35 | return Optional.of(Direction.N); | ||
36 | case MOVE_E: | ||
37 | return Optional.of(Direction.E); | ||
38 | case MOVE_S: | ||
39 | return Optional.of(Direction.S); | ||
40 | case MOVE_W: | ||
41 | return Optional.of(Direction.W); | ||
42 | case STOP: | ||
43 | return Optional.empty(); | ||
44 | default: | ||
45 | return null; | ||
46 | } | ||
47 | } | ||
18 | 48 | ||
19 | } | 49 | } |