コード例 #1
0
ファイル: Server.cs プロジェクト: FergusGriggs/FormsServer
        private void ProcessGameInputRPS(String input, int clientID, ref List <int> recievers, ref List <String> messages)
        {
            char inputChar = input.ToUpper()[0];

            if (inputChar == 'R' || inputChar == 'P' || inputChar == 'S')
            {
                bool alreadyPlayed = false;
                bool isClient1     = false;
                Game clientGame    = _clients[clientID].GetCurrentGame();
                if (clientGame.GetClient1() == _clients[clientID])
                {
                    isClient1 = true;
                    if (!clientGame.GetClient1Inputted())
                    {
                        clientGame.SetClient1Input(inputChar.ToString());
                    }
                    else
                    {
                        alreadyPlayed = true;
                    }
                }
                else
                {
                    if (!clientGame.GetClient2Inputted())
                    {
                        clientGame.SetClient2Input(inputChar.ToString());
                    }
                    else
                    {
                        alreadyPlayed = true;
                    }
                }

                if (alreadyPlayed)
                {
                    recievers.Add(clientID);
                    messages.Add("You've already played num nutz");
                }
                else
                {
                    if (clientGame.GetClient1Inputted() && clientGame.GetClient2Inputted())
                    {
                        String client1Message = "", client2Message = "";

                        clientGame.GetRPSResult(ref client1Message, ref client2Message);

                        if (isClient1)
                        {
                            recievers.Add(clientID);
                            messages.Add("<777700You played " + GetRPSFullName(inputChar) + ">\n" + client1Message);

                            recievers.Add(clientGame.GetClient2().GetID());
                            messages.Add(client2Message);
                        }
                        else
                        {
                            recievers.Add(clientGame.GetClient1().GetID());
                            messages.Add(client1Message);

                            recievers.Add(clientID);
                            messages.Add("<777700You played " + GetRPSFullName(inputChar) + ">\n" + client2Message);
                        }
                        clientGame.NextRound();
                    }
                    else
                    {
                        recievers.Add(clientID);
                        messages.Add("<777700You played " + GetRPSFullName(inputChar) + ">");
                    }
                }
            }
            else
            {
                recievers.Add(clientID);
                messages.Add("Invalid Input my dude");
            }
        }