Package com.music.web.websocket.dto

Examples of com.music.web.websocket.dto.GameMessage


        Assert.assertEquals(game.getId(), response.getGameId());
    }

    private void initializeGame(GameHandler handler) {
        try {
            GameMessage msg = new GameMessage();
            msg.setAction(GameAction.INITIALIZE);
            msg.setPlayerName("Game starter");
            TextMessage message = getTextMessage(msg);
            WebSocketSession session = getSession("1");

            handler.afterConnectionEstablished(session);
            handler.handleMessage(session, message);
View Full Code Here


        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

        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

        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

    }

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) throws Exception {
        try {
            GameMessage message = getMessage(textMessage);
            switch(message.getAction()) {
                case INITIALIZE: initialize(message, session); break;
                case JOIN: join(message.getGameId(), message.getPlayerName(), session); break;
                case LEAVE: leave(session.getId()); break;
                case START: startGame(message); break;
                case ANSWER: answer(message, session.getId()); break;
                case JOIN_RANDOM: joinRandomGame(message.getPlayerName(), session); break;
            }
        } catch (Exception ex) {
            logger.error("Exception occurred while handling message", ex);
        }
    }
View Full Code Here

TOP

Related Classes of com.music.web.websocket.dto.GameMessage

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.