Exemple #1
0
        protected void SendGameStart()
        {
            SGUpdateMsg StartGameMsg = new SGUpdateMsg();

            StartGameMsg.SGID        = XPlayer.Gamepad.SGID;
            StartGameMsg.MessageType = "start";
            StartGameMsg.Data        = new JSONObject();

            StartGameMsg.Data.AddField("mark", 1);
            StartGameMsg.Serialize();

            Debug.Log("Sending 'start': " + StartGameMsg.ToString());
            socket.Emit("SGUpdateMsg", StartGameMsg);

            StartGameMsg.SGID = OPlayer.Gamepad.SGID;
            StartGameMsg.Data.SetField("mark", 2);
            StartGameMsg.Serialize();
            Debug.Log("Sending 'start': " + StartGameMsg.ToString());
            socket.Emit("SGUpdateMsg", StartGameMsg);
        }
Exemple #2
0
        protected void SendMyTurn()
        {
            SGUpdateMsg MyTurnMsg = new SGUpdateMsg();

            MyTurnMsg.SGID        = PlayerTurn == 1 ? XPlayer.Gamepad.SGID : OPlayer.Gamepad.SGID;
            MyTurnMsg.MessageType = "turn";
            MyTurnMsg.Data        = new JSONObject();
            MyTurnMsg.Serialize();

            Debug.Log("Sending 'turn': " + MyTurnMsg.ToString());
            socket.Emit("SGUpdateMsg", MyTurnMsg);
        }
Exemple #3
0
        protected void SendGameEnd()
        {
            SGUpdateMsg ResetGameMsg = new SGUpdateMsg();

            ResetGameMsg.SGID        = -1;
            ResetGameMsg.MessageType = "finish";
            ResetGameMsg.Data        = new JSONObject();
            ResetGameMsg.Data.AddField("winner", Winner > 2 ? 0 : Winner);
            ResetGameMsg.Serialize();

            Debug.Log("Sending 'finish': " + ResetGameMsg.ToString());

            socket.Emit("SGUpdateMsg", ResetGameMsg);
        }
Exemple #4
0
        protected void SendGameState(SocketGamepad gamepad)
        {
            SGUpdateMsg     GameStateMsg = new SGUpdateMsg();
            TicTacToePlayer tttPlayer    = (TicTacToePlayer)ActiveGamepads[gamepad];

            GameStateMsg.SGID        = tttPlayer.PlayerId;
            GameStateMsg.MessageType = "gamestate";
            GameStateMsg.Data        = new JSONObject();
            JSONObject CellJSON = new JSONObject(JSONObject.Type.ARRAY);

            GameStateMsg.Data.AddField("mark", tttPlayer.Xs ? 1 : 2);
            for (int m = 0; m < 9; m++)
            {
                CellJSON.list.Add(new JSONObject(Grid[m].CurrentMark));
            }
            GameStateMsg.Data.AddField("cells", CellJSON);
            GameStateMsg.Serialize();

            Debug.Log("Sending Game State: " + GameStateMsg.ToString());

            socket.Emit("SGUpdateMsg", GameStateMsg);
        }