aboutsummaryrefslogtreecommitdiff
path: root/test/ch
diff options
context:
space:
mode:
Diffstat (limited to 'test/ch')
-rw-r--r--test/ch/epfl/xblast/client/PlayerTest.java40
-rw-r--r--test/ch/epfl/xblast/simulation/GraphicalSimulation.java19
2 files changed, 41 insertions, 18 deletions
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 @@
1package ch.epfl.xblast.client;
2
3import ch.epfl.xblast.Lists;
4import ch.epfl.xblast.PlayerID;
5import ch.epfl.xblast.SubCell;
6import org.junit.Assert;
7import org.junit.Test;
8
9import java.util.Arrays;
10import java.util.List;
11
12/**
13 * @author Timothée FLOURE (257420)
14 */
15public class PlayerTest {
16
17 private static final GameState.Player PLAYER_1 = new GameState.Player(PlayerID.PLAYER_1, 5, new SubCell(1,50), null);
18 private static final GameState.Player PLAYER_2 = new GameState.Player(PlayerID.PLAYER_2, 5, new SubCell(20,20), null);
19 private static final GameState.Player PLAYER_3 = new GameState.Player(PlayerID.PLAYER_3, 5, new SubCell(20,20), null);
20 private static final GameState.Player PLAYER_4 = new GameState.Player(PlayerID.PLAYER_4, 5, new SubCell(30,10), null);
21
22 private static final PlayerID CURRENT_PLAYER = PlayerID.PLAYER_3;
23
24
25 @Test
26 public void clientPlayerOder() {
27 List<GameState.Player> players = Arrays.asList(PLAYER_1,PLAYER_2,PLAYER_3,PLAYER_4);
28 List<GameState.Player> expectedOrder = Arrays.asList(PLAYER_4,PLAYER_2,PLAYER_3,PLAYER_1);
29
30 // Order the players
31 List<GameState.Player> computedOrder = Lists.sorted(
32 players,
33 GameState.Player
34 .POSITION_COMPARATOR
35 .thenComparing(GameState.Player.idPushingComparator(CURRENT_PLAYER)));
36
37 // Assert
38 Assert.assertEquals(expectedOrder,computedOrder);
39 }
40}
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;
12 12
13import javax.swing.*; 13import javax.swing.*;
14import java.awt.*; 14import java.awt.*;
15import java.awt.event.KeyEvent;
16import java.util.Collections;
17import java.util.HashMap;
18import java.util.List; 15import java.util.List;
19import java.util.Map;
20import java.util.function.Consumer; 16import java.util.function.Consumer;
21 17
22/** 18/**
@@ -31,19 +27,6 @@ public class GraphicalSimulation extends Simulation {
31 private static final Consumer<PlayerAction> PLAYER_ACTION_CONSUMER = System.out::println; 27 private static final Consumer<PlayerAction> PLAYER_ACTION_CONSUMER = System.out::println;
32 private static final PlayerID MAIN_PLAYER = PlayerID.PLAYER_1; 28 private static final PlayerID MAIN_PLAYER = PlayerID.PLAYER_1;
33 29
34 private static Map<Integer, PlayerAction> buildPlayerActionMap() {
35 Map<Integer, PlayerAction> playerActionMap = new HashMap<>();
36
37 playerActionMap.put(KeyEvent.VK_UP, PlayerAction.MOVE_N);
38 playerActionMap.put(KeyEvent.VK_RIGHT, PlayerAction.MOVE_E);
39 playerActionMap.put(KeyEvent.VK_DOWN, PlayerAction.MOVE_S);
40 playerActionMap.put(KeyEvent.VK_LEFT, PlayerAction.MOVE_W);
41 playerActionMap.put(KeyEvent.VK_SPACE, PlayerAction.DROP_BOMB);
42 playerActionMap.put(KeyEvent.VK_SHIFT, PlayerAction.STOP);
43
44 return Collections.unmodifiableMap(playerActionMap);
45 }
46
47 private static ch.epfl.xblast.client.GameState translateToClientData(GameState gs) { 30 private static ch.epfl.xblast.client.GameState translateToClientData(GameState gs) {
48 List<Byte> serializedGameState = GameStateSerializer.serialize(BOARD_PAINTER, gs); 31 List<Byte> serializedGameState = GameStateSerializer.serialize(BOARD_PAINTER, gs);
49 return GameStateDeserializer.deserialize(serializedGameState); 32 return GameStateDeserializer.deserialize(serializedGameState);
@@ -61,7 +44,7 @@ public class GraphicalSimulation extends Simulation {
61 } 44 }
62 45
63 private void attachKeyboardHandler(Component comp) { 46 private void attachKeyboardHandler(Component comp) {
64 comp.addKeyListener(new KeyboardEventHandler(buildPlayerActionMap(), PLAYER_ACTION_CONSUMER)); 47 comp.addKeyListener(new KeyboardEventHandler(PLAYER_ACTION_CONSUMER));
65 comp.requestFocusInWindow(); 48 comp.requestFocusInWindow();
66 } 49 }
67 50