From 48d8fc2efc91f5a02391fb1031e7a662509f5630 Mon Sep 17 00:00:00 2001 From: Pacien TRAN-GIRARD Date: Wed, 11 May 2016 22:45:02 +0200 Subject: Implement client --- .../epfl/xblast/simulation/GraphicalSimulation.java | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/simulation/GraphicalSimulation.java b/test/ch/epfl/xblast/simulation/GraphicalSimulation.java index 9329cc7..1d15fe5 100644 --- a/test/ch/epfl/xblast/simulation/GraphicalSimulation.java +++ b/test/ch/epfl/xblast/simulation/GraphicalSimulation.java @@ -12,11 +12,7 @@ import ch.epfl.xblast.server.painter.BoardPainter; import javax.swing.*; import java.awt.*; -import java.awt.event.KeyEvent; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.function.Consumer; /** @@ -31,19 +27,6 @@ public class GraphicalSimulation extends Simulation { private static final Consumer PLAYER_ACTION_CONSUMER = System.out::println; private static final PlayerID MAIN_PLAYER = PlayerID.PLAYER_1; - private static Map buildPlayerActionMap() { - Map playerActionMap = new HashMap<>(); - - playerActionMap.put(KeyEvent.VK_UP, PlayerAction.MOVE_N); - playerActionMap.put(KeyEvent.VK_RIGHT, PlayerAction.MOVE_E); - playerActionMap.put(KeyEvent.VK_DOWN, PlayerAction.MOVE_S); - playerActionMap.put(KeyEvent.VK_LEFT, PlayerAction.MOVE_W); - playerActionMap.put(KeyEvent.VK_SPACE, PlayerAction.DROP_BOMB); - playerActionMap.put(KeyEvent.VK_SHIFT, PlayerAction.STOP); - - return Collections.unmodifiableMap(playerActionMap); - } - private static ch.epfl.xblast.client.GameState translateToClientData(GameState gs) { List serializedGameState = GameStateSerializer.serialize(BOARD_PAINTER, gs); return GameStateDeserializer.deserialize(serializedGameState); @@ -61,7 +44,7 @@ public class GraphicalSimulation extends Simulation { } private void attachKeyboardHandler(Component comp) { - comp.addKeyListener(new KeyboardEventHandler(buildPlayerActionMap(), PLAYER_ACTION_CONSUMER)); + comp.addKeyListener(new KeyboardEventHandler(PLAYER_ACTION_CONSUMER)); comp.requestFocusInWindow(); } -- cgit v1.2.3 From 43230122b99b5fd5b60fb9b181cb0bef65104c6b Mon Sep 17 00:00:00 2001 From: Timothée Floure Date: Mon, 23 May 2016 14:32:16 +0200 Subject: Basic test for the order of the players to be displayed (client) --- test/ch/epfl/xblast/client/PlayerTest.java | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/ch/epfl/xblast/client/PlayerTest.java (limited to 'test/ch/epfl') diff --git a/test/ch/epfl/xblast/client/PlayerTest.java b/test/ch/epfl/xblast/client/PlayerTest.java new file mode 100644 index 0000000..fdf065e --- /dev/null +++ b/test/ch/epfl/xblast/client/PlayerTest.java @@ -0,0 +1,40 @@ +package ch.epfl.xblast.client; + +import ch.epfl.xblast.Lists; +import ch.epfl.xblast.PlayerID; +import ch.epfl.xblast.SubCell; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Arrays; +import java.util.List; + +/** + * @author Timothée FLOURE (257420) + */ +public class PlayerTest { + + private static final GameState.Player PLAYER_1 = new GameState.Player(PlayerID.PLAYER_1, 5, new SubCell(1,50), null); + private static final GameState.Player PLAYER_2 = new GameState.Player(PlayerID.PLAYER_2, 5, new SubCell(20,20), null); + private static final GameState.Player PLAYER_3 = new GameState.Player(PlayerID.PLAYER_3, 5, new SubCell(20,20), null); + private static final GameState.Player PLAYER_4 = new GameState.Player(PlayerID.PLAYER_4, 5, new SubCell(30,10), null); + + private static final PlayerID CURRENT_PLAYER = PlayerID.PLAYER_3; + + + @Test + public void clientPlayerOder() { + List players = Arrays.asList(PLAYER_1,PLAYER_2,PLAYER_3,PLAYER_4); + List expectedOrder = Arrays.asList(PLAYER_4,PLAYER_2,PLAYER_3,PLAYER_1); + + // Order the players + List computedOrder = Lists.sorted( + players, + GameState.Player + .POSITION_COMPARATOR + .thenComparing(GameState.Player.idPushingComparator(CURRENT_PLAYER))); + + // Assert + Assert.assertEquals(expectedOrder,computedOrder); + } +} -- cgit v1.2.3