Beispiel #1
0
        // Match whatever WebSocket text is sending
        // Consistency: General rule here is that the game state if not timestamped, events may not represent the same time window.
        void HandleMessage(string message)
        {
            var msg = MessageWrapper.UnWrapMessage(message);

            // Not quite symetric, but the server is text only.
            switch (msg.type)
            {
            case "qotd":
                break;

            case "notification":
                Notification notification = Messaging <Notification> .Deserialize(message);

                clog(notification.notificationText);
                break;

            case "register":
                GameRegister register = Messaging <GameRegister> .Deserialize(message);

                gameSession.sessionId  = register.sessionId;
                gameSession.uuidPlayer = register.uuidPlayer;
                break;

            case "gameJoin":
                GameJoin gj = Messaging <GameJoin> .Deserialize(message);

                JoinGame(gj);
                break;

            case "scoreEvent":
                ScoreEvent se = Messaging <ScoreEvent> .Deserialize(message);

                UpdateScore(se);
                break;

            case "moveEvent":
                MoveEvent me = Messaging <MoveEvent> .Deserialize(message);

                UpdatePosition(me);
                break;

            case "gameState":
                GameState serverGs = Messaging <GameState> .Deserialize(message);

                gameSession.currentGs.sequence = serverGs.sequence;
                //UpdateLocalGame(serverGs);
                break;

            case "contactEvent":
                ContactEvent ce = Messaging <ContactEvent> .Deserialize(message);

                HandleContactEvent(ce);
                break;

            case "resign":
                GameResign resign = Messaging <GameResign> .Deserialize(message);

                theBall.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
                ghostBall.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
                break;

            case "nextRound":
                NextRound nr = Messaging <NextRound> .Deserialize(message);

                StartNextRound(nr);
                break;

            case "gameRestart":
                GameRestart gr = Messaging <GameRestart> .Deserialize(message);

                RestartGame(gr);
                break;

            default:
                clog("Unknown message arrived: " + msg.type + ", message: " + message);
                break;
            }
        }