Examples of GameMessage


Examples of com.jcloisterzone.wsio.message.GameMessage

        return msg;
    }

    private GameMessage newGameMessage() {
        GameSetupMessage gsm = new GameSetupMessage(game.getGameId(), game.getCustomRules(), game.getExpansions(), game.getCapabilityClasses());
        GameMessage gm = new GameMessage(game.getGameId(), "", gameStarted ? GameState.RUNNING : GameState.OPEN, gsm);
        List<SlotMessage> slotMsgs = new ArrayList<>();
        for (ServerPlayerSlot slot : slots) {
            if (slot != null) {
                SlotMessage sm = newSlotMessage(slot);
                slotMsgs.add(sm);
            }
        }
        gm.setSlots(slotMsgs.toArray(new SlotMessage[slotMsgs.size()]));
        if (snapshot != null) {
            try {
                gm.setSnapshot(snapshot.saveToString());
            } catch (TransformerException | IOException e) {
                logger.error(e.getMessage(), e);
            }
        }
        return gm;
View Full Code Here

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

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

        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

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

        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

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

        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

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

    }

    @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
Copyright © 2018 www.massapi.com. 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.