Advertisement
Guest User

Untitled

a guest
May 27th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.15 KB | None | 0 0
  1.  
  2.     @Test
  3.     public void testEndGameOnePlayer() throws Exception {
  4.         AtomicReference<Boolean> failedUpdateFood = new AtomicReference<Boolean>(true);
  5.         AtomicReference<Boolean> failedUpdate = new AtomicReference<Boolean>(true);
  6.         AtomicReference<Boolean> failedStartGame = new AtomicReference<Boolean>(true);
  7.         AtomicReference<Boolean> failedHideButton = new AtomicReference<Boolean>(true);
  8.         AtomicReference<Boolean> failedRoomAdmin = new AtomicReference<Boolean>(true);
  9.  
  10.         AtomicReference<Boolean> startedGame = new AtomicReference<Boolean>(false);
  11.  
  12.         AtomicReference<Integer> n = new AtomicReference<Integer>(0);
  13.         int nPlayers = 4;
  14.         WebSocketClient players[] = new WebSocketClient[nPlayers];
  15.  
  16.         for (int i = 0; i < nPlayers; i++) {
  17.             WebSocketClient w = new WebSocketClient();
  18.            
  19.             if (i == 0) {
  20.                 w.sendMessage("{\"op\":\"createGame\",\"value\":\"room1\",\"dif\":\"1\",\"gameMode\":\"1\"}");
  21.                 w.admin  = true;
  22.             }
  23.             w.onMessage((session, msg) -> {
  24.                 if( !startedGame.get() && msg.contains("updateFood") || msg.contains("update") || msg.contains("hideStartButton")){
  25.                     startedGame.set(true);
  26.                 }
  27.                 if (msg.contains("newRoomCreator")) {
  28.                     try {
  29.                         w.sendMessage("{\"op\":\"JoinGame\",\"value\":\"room1\"}");
  30.                     } catch (IOException ex) {System.out.println("Error al enviar el mensaje de JoingGame tras crear room1"); }
  31.                    
  32.                 }else if(!startedGame.get() && msg.contains("join")){
  33.                     //int nPlayersOnline = (msg.length() - msg.replaceAll("id","").length())/2;
  34.                     w.join= true;
  35.                     if(w.admin){
  36.                         try{
  37.                             w.sendMessage("{\"op\":\"startGame\"}");
  38.                         } catch (IOException ex) {System.out.println("Error al enviar el mensaje de StartGame tras recibir Join"); }
  39.                     }
  40.                 }
  41.                
  42.             });
  43.  
  44.         }
  45.  
  46.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement