aboutsummaryrefslogtreecommitdiff
path: root/test/ch/epfl
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2016-05-11 22:45:02 +0200
committerPacien TRAN-GIRARD2016-05-11 22:45:02 +0200
commit48d8fc2efc91f5a02391fb1031e7a662509f5630 (patch)
tree4f78dffe979846421fbbccc9dc798a767dd6fb32 /test/ch/epfl
parent33bc4cab3f2a00db14e6d055d6cd55781c9dd2b4 (diff)
downloadxblast-48d8fc2efc91f5a02391fb1031e7a662509f5630.tar.gz
Implement client
Diffstat (limited to 'test/ch/epfl')
-rw-r--r--test/ch/epfl/xblast/simulation/GraphicalSimulation.java19
1 files changed, 1 insertions, 18 deletions
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