示例#1
0
        private void ParseMessage(string message)
        {
            string[] data = message.Split(';');

            switch (data[0])
            {
            // data[1] player number
            // data[2] value
            // data[3] suit
            case "move":
                SendForbidPlay();

                if (gameManager.IsMoveValid(Convert.ToInt32(data[1]), data[2], data[3]) == false)
                {
                    string msg = "invalid_move;";
                    foreach (NetworkStream ns in networkStreams)
                    {
                        SendMessage(Encoding.ASCII.GetBytes(msg), ns);
                    }

                    SendAllowPlay();

                    break;
                }

                gameManager.PlayerMove(Convert.ToInt32(data[1]), data[2], data[3]);

                foreach (NetworkStream networkStream in networkStreams)
                {
                    SendMessage(Encoding.ASCII.GetBytes(message), networkStream);
                }

                CheckIfTurnEnd();
                CheckIfRoundEnd();
                SendAllowPlay();
                break;

            case "start_game":
                if (isServerFull)
                {
                    SendMessageStartGame();
                }
                else
                {
                    SendErrorMessage("Not enough players are connected to start game!");
                }
                break;

            case "player_exit":
                numberOfConnectedPlayers--;
                isServerFull = false;
                gameManager.ResetGame();
                break;

            default:
                break;
            }
        }