Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Test
- public void testEndGameOnePlayer() throws Exception {
- AtomicReference<Boolean> failedUpdateFood = new AtomicReference<Boolean>(true);
- AtomicReference<Boolean> failedUpdate = new AtomicReference<Boolean>(true);
- AtomicReference<Boolean> failedStartGame = new AtomicReference<Boolean>(true);
- AtomicReference<Boolean> failedHideButton = new AtomicReference<Boolean>(true);
- AtomicReference<Boolean> failedRoomAdmin = new AtomicReference<Boolean>(true);
- AtomicReference<Boolean> startedGame = new AtomicReference<Boolean>(false);
- AtomicReference<Integer> n = new AtomicReference<Integer>(0);
- int nPlayers = 4;
- WebSocketClient players[] = new WebSocketClient[nPlayers];
- for (int i = 0; i < nPlayers; i++) {
- WebSocketClient w = new WebSocketClient();
- if (i == 0) {
- w.sendMessage("{\"op\":\"createGame\",\"value\":\"room1\",\"dif\":\"1\",\"gameMode\":\"1\"}");
- w.admin = true;
- }
- w.onMessage((session, msg) -> {
- if( !startedGame.get() && msg.contains("updateFood") || msg.contains("update") || msg.contains("hideStartButton")){
- startedGame.set(true);
- }
- if (msg.contains("newRoomCreator")) {
- try {
- w.sendMessage("{\"op\":\"JoinGame\",\"value\":\"room1\"}");
- } catch (IOException ex) {System.out.println("Error al enviar el mensaje de JoingGame tras crear room1"); }
- }else if(!startedGame.get() && msg.contains("join")){
- //int nPlayersOnline = (msg.length() - msg.replaceAll("id","").length())/2;
- w.join= true;
- if(w.admin){
- try{
- w.sendMessage("{\"op\":\"startGame\"}");
- } catch (IOException ex) {System.out.println("Error al enviar el mensaje de StartGame tras recibir Join"); }
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement