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 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; } } }