aboutsummaryrefslogtreecommitdiff
path: root/src/ch
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-11 13:41:25 +0200
committerPacien TRAN-GIRARD2016-05-11 13:41:25 +0200
commit2392d36dfa15a262d69aeb6356408d90d5a32ab2 (patch)
tree5470feb6447ff2c384a5d441a8cf164e68ced175 /src/ch
parentf213ff8993588a9a0d63946e8a4f9b6975de3c95 (diff)
downloadxblast-2392d36dfa15a262d69aeb6356408d90d5a32ab2.tar.gz
Add PlayerAction and PlayerID byte conversion
Diffstat (limited to 'src/ch')
-rw-r--r--src/ch/epfl/xblast/PlayerAction.java13
-rw-r--r--src/ch/epfl/xblast/PlayerID.java13
2 files changed, 25 insertions, 1 deletions
diff --git a/src/ch/epfl/xblast/PlayerAction.java b/src/ch/epfl/xblast/PlayerAction.java
index 703bc9d..67920eb 100644
--- a/src/ch/epfl/xblast/PlayerAction.java
+++ b/src/ch/epfl/xblast/PlayerAction.java
@@ -14,6 +14,17 @@ public enum PlayerAction {
14 MOVE_S, 14 MOVE_S,
15 MOVE_W, 15 MOVE_W,
16 STOP, 16 STOP,
17 DROP_BOMB 17 DROP_BOMB;
18
19 public static PlayerAction fromByte(byte b) {
20 if ((int) b < 0 || (int) b >= PlayerAction.values().length)
21 throw new IllegalArgumentException();
22
23 return PlayerAction.values()[(int) b];
24 }
25
26 public byte toByte() {
27 return (byte) this.ordinal();
28 }
18 29
19} 30}
diff --git a/src/ch/epfl/xblast/PlayerID.java b/src/ch/epfl/xblast/PlayerID.java
index 9377fdf..96b98e4 100644
--- a/src/ch/epfl/xblast/PlayerID.java
+++ b/src/ch/epfl/xblast/PlayerID.java
@@ -13,6 +13,8 @@ public enum PlayerID {
13 PLAYER_3, 13 PLAYER_3,
14 PLAYER_4; 14 PLAYER_4;
15 15
16 public static final byte OBSERVER = -1;
17
16 public Cell initialPosition() { 18 public Cell initialPosition() {
17 switch (this) { 19 switch (this) {
18 case PLAYER_1: 20 case PLAYER_1:
@@ -28,4 +30,15 @@ public enum PlayerID {
28 } 30 }
29 } 31 }
30 32
33 public static PlayerID fromByte(byte b) {
34 if ((int) b < 0 || (int) b >= PlayerAction.values().length)
35 throw new IllegalArgumentException();
36
37 return PlayerID.values()[(int) b];
38 }
39
40 public byte toByte() {
41 return (byte) this.ordinal();
42 }
43
31} 44}