Exemple #1
0
        /// <summary>
        /// Xử lí dữ liệu
        /// </summary>
        /// <param name="client"></param>
        /// <param name="message"></param>
        private void ProcessData(Socket client, Message message)
        {
            string  roomID = "";
            Room    room;
            Message mes;
            int     sttPlayer;

            switch (message.Opcode)
            {
            case 101:
                AddPlayer(client, message);
                roomID = listPlayer[message.Sender].RoomID;
                room   = listRoom[roomID];
                if (room.ListPlayer.Count == 3)
                {
                    StartGame(room, client);
                }
                break;

            case 111:
                roomID = listPlayer[message.Sender].RoomID;
                room   = listRoom[roomID];

                sttPlayer = room.ListPlayer.IndexOf(listPlayer[message.Sender]) + 1;
                if (room.Turn == sttPlayer)
                {
                    mes = new Message(221, message.Sender, message.Payload);
                    server.SendAllRoom(room, mes.ToString());
                    room.Turn = (room.Turn + 1);
                    if (room.Turn > 3)
                    {
                        room.Turn = 1;
                    }
                    SendTurnPlay(room);
                }
                break;

            case 112:
                roomID = listPlayer[message.Sender].RoomID;
                room   = listRoom[roomID];

                sttPlayer = room.ListPlayer.IndexOf(listPlayer[message.Sender]) + 1;
                if (room.Turn == sttPlayer)
                {
                    mes = new Message(222, message.Sender, message.Payload);
                    server.SendAllRoom(room, mes.ToString());
                    room.Turn = (room.Turn + 1);
                    if (room.Turn > 3)
                    {
                        room.Turn = 1;
                    }
                    SendTurnPlay(room);
                }
                break;

            default:
                //sai cú pháp
                break;
            }
        }