public bool RestartGame(GameRestart gr)
        {
            clog("Restarting game, gameId: " + gr.gameId);
            if (gr.gameId != networkManager.gameSession.gameId)
            {
                return(false);
            }
            networkManager.gameSession.status = STATUS.RESTART;

            //theBall.SendMessage("ResetBall", null, SendMessageOptions.RequireReceiver);
            PlayerScore1 = 0;
            PlayerScore2 = 0;

            networkManager.gameSession.currentGs.sequence = 0;
            networkManager.gameSession.status             = STATUS.INGAME;

            // The ball position and velocity is chosen at random by server, and sent out to players.
            // For now, just trust it.
            BallControl bc = theBall.GetComponent <BallControl>();

            bc.setPosition(new Position(Vector2.zero));
            bc.setVelocity(new Velocity(Vector2.zero));
            // Not correct. FIXME:
            Vector2 startingForce = new Vector2(gr.balls[0].velocity.x, gr.balls[0].velocity.y);

            // Not deterministic?
            //bc.rb2d.AddForce(startingForce);

            bc.setVelocity(gr.balls[0].velocity);

            return(false);
        }
        public void SendRestart()
        {
            GameRestart gr = new GameRestart();

            gr.gameId   = networkManager.gameSession.gameId;
            gr.balls    = new Ball[1];
            gr.balls[0] = Ball.CopyBall(theBall.GetComponent <BallControl>());
            networkManager.webSocketClient.Send(Messaging <GameRestart> .Serialize(gr));
        }
예제 #3
0
        void SendRestart()
        {
            GameRestart gr = new GameRestart();

            gr.gameId   = gameSession.gameId;
            gr.balls    = new Ball[1];
            gr.balls[0] = Ball.CopyBall(theBall.GetComponent <BallControl>());
            client.Send(Messaging <GameRestart> .Serialize(gr));
        }
예제 #4
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);

                gameManager.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);

                gameManager.JoinGame(gj);
                break;

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

                gameManager.UpdateScore(se);
                break;

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

                gameManager.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);

                gameManager.HandleContactEvent(ce);
                break;

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

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

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

                gameManager.StartNextRound(nr);
                break;

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

                gameManager.RestartGame(gr);
                break;

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