diff options
author | Timothée Floure | 2016-05-27 13:47:51 +0200 |
---|---|---|
committer | Timothée Floure | 2016-05-27 13:47:51 +0200 |
commit | e7382c3c2a28109b18492e9a62265c51b1be94dd (patch) | |
tree | 68b75b4968f74ddde01d012cccc5cf596a823ec0 /src/ch/epfl/xblast/PlayerAction.java | |
parent | 7d9c28e25d5b0965171f4b347852a11fdf01482e (diff) | |
parent | a82a8ba2611378ff6fb1cd226fb3d579d43d6e89 (diff) | |
download | xblast-e7382c3c2a28109b18492e9a62265c51b1be94dd.tar.gz |
11 network
See merge request !11
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 | } |