Package com.music.web.websocket

Examples of com.music.web.websocket.Game


        GameEvent response = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
        Assert.assertEquals(GameEventType.GAME_INITIALIZED, response.getType());

        Assert.assertEquals(1, handler.getGames().size());

        Game game = handler.getGames().values().iterator().next();
        Assert.assertEquals(game.getId(), response.getGameId());
    }
View Full Code Here


        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();

        GameMessage startMsg = new GameMessage();
        startMsg.setAction(GameAction.START);
        startMsg.setGameId(game.getId());

        WebSocketSession session = getSession("1");
        handler.handleMessage(session, getTextMessage(startMsg));

        GameEvent responseNewPiece = mapper.readValue(messages.get("1").removeLast().getPayload().toString(), GameEvent.class);
View Full Code Here

        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();

        GameMessage playerJoinMsg = new GameMessage();
        playerJoinMsg.setAction(GameAction.JOIN);
        playerJoinMsg.setPlayerName("AAA");
        playerJoinMsg.setGameId(game.getId());

        getSession("1");
        WebSocketSession player2Session = getSession("2");

        handler.afterConnectionEstablished(player2Session);
View Full Code Here

        Assert.assertTrue(messages.get("2").size() == 1); // player received a 'player_joined' event for each other player in the game
    }

    @Test
    public void derivedMetreTest() {
        Game game = new Game("1", null);
        Piece piece = new Piece();
        piece.setMetreNumerator(4);
        piece.setMetreDenominator(4);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {8, 8}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {4, 8}));

        piece.setMetreNumerator(8);
        piece.setMetreDenominator(8);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {4, 4}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {2, 4}));

        piece.setMetreNumerator(2);
        piece.setMetreDenominator(4);
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {4, 8}));
        Assert.assertFalse(game.isNotDerivedMetre(piece, new int[] {2, 4}));
        Assert.assertTrue(game.isNotDerivedMetre(piece, new int[] {4, 4}));

    }
View Full Code Here

    public void gameFinishedTest() throws Exception {
        GameHandler handler = new GameHandler();
        handler.setPieceService(pieceServiceMock);

        initializeGame(handler);
        Game game = handler.getGames().values().iterator().next();


        GameMessage playerJoinMsg = new GameMessage();
        playerJoinMsg.setAction(GameAction.JOIN);
        playerJoinMsg.setPlayerName("AAA");
        playerJoinMsg.setGameId(game.getId());
        WebSocketSession session = getSession("1");

        handler.handleMessage(session, getTextMessage(playerJoinMsg));
        game.setSecondsBeforeNextPiece(0);

        // Answer all three questions
        for (int i = 0; i < 3; i ++) {
            game.sendNextPiece();
            GameMessage answerMsg = new GameMessage();
            answerMsg.setAction(GameAction.ANSWER);
            com.music.web.websocket.dto.Answer answer = new com.music.web.websocket.dto.Answer();
            answer.setMainInstrument(0);
            answer.setMetreNumerator(2);
            answer.setMetreDenominator(4);
            answer.setTempo(80);
            answerMsg.setAnswer(answer);
            answerMsg.setGameId(game.getId());
            handler.handleMessage(session, getTextMessage(answerMsg));
        }
        Assert.assertFalse(game.isStarted());
        Assert.assertTrue(game.getResults().getRanking().contains("1"));
        Assert.assertTrue(game.getResults().getScores().containsKey(playerJoinMsg.getPlayerName()));
    }
View Full Code Here

    }

    @MessageMapping("/join")
    @ResponseBody
    public void joinGame(String gameId, Principal principal) {
        Game game = games.get(gameId);
        if (game != null && !game.isStarted()) {
            addCurrentUser(game, principal);
        } else {
            // Game doesn't exist or is already started
        }
    }
View Full Code Here

TOP

Related Classes of com.music.web.websocket.Game

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.