Ejemplo n.º 1
0
        /// <summary>
        /// Selectで送られてきたデータの処理と次のプレイヤーへの受け渡し。
        /// </summary>
        /// <param name="player"></param>
        /// <param name="Content">CardIDの,区切り</param>
        void GameProsess(Player player, string Content)
        {
            player.Turn = false;

            string[] CardIDArray = Content.Split(',');
            //Playerの手札と照合
            List <int> PlayerHand = player.Hand;
            bool       NotExist   = false;

            foreach (string CardID in CardIDArray)
            {
                if (!PlayerHand.Exists(x => x == int.Parse(CardID)))
                {
                    NotExist = true;
                    break;
                }
                PlayerHand.Remove(int.Parse(CardID));
            }
            //選択したカードに手札以外が含まれている。
            if (NotExist)
            {
                SendData(player, SendParameter.Error, "CardDoesntExist");
                SendData(player, SendParameter.Hand, player.GetHand());
                player.Turn = true;
                SendData(player, SendParameter.Turn, "0");
            }
            if (IsAppropriate(CardIDArray))
            {
                SendDataAllPlayer(SendParameter.DrawPile, Content);
                TopDrawCard = int.Parse(CardIDArray[CardIDArray.Length - 1]);
                player.Hand = PlayerHand;
                SendData(player, SendParameter.Hand, player.GetHand());
                if (player.Hand.Count == 0)
                {
                    SendData(player, SendParameter.Finish, "Win");
                    SendData(GetOtherPlayers(player)[0], SendParameter.Finish, "Lose");
                    Console.WriteLine("We Finish the Game.");
                }
                else
                {
                    GetOtherPlayers(player)[0].Turn = true;
                    SendData(GetOtherPlayers(player)[0], SendParameter.Turn, "0");
                }
            }
            else
            {
                SendData(player, SendParameter.Hand, player.GetHand());
                GetOtherPlayers(player)[0].Turn = true;
                SendData(player, SendParameter.Turn, "0");
            }
        }
Ejemplo n.º 2
0
        protected override void OnReceive(StateObject stateObject, string Msg)
        {
            Player player   = GetPlayer(stateObject.ClientSocket);
            Player opponent = default;

            if (GetOtherPlayers(player).Count != 0)
            {
                opponent = GetOtherPlayers(player)[0];
            }


            string[] MsgSplit  = Msg.Split('=');
            string   Parameter = MsgSplit[0];
            string   Content   = MsgSplit[1];

            switch (Parameter)
            {
            case "PlayerName":
                if (!player.SetName(Content))
                {
                    SendData(player, SendParameter.Error, "AlreadySetPlayerName");
                }
                break;

            case "Select":
                GameProsess(player, Content);
                break;

            case "Draw":
                if (player.Turn)
                {
                    Distribute(player, int.Parse(Content));
                }
                Distribute(player, int.Parse(Content));
                SendData(player, SendParameter.Hand, player.GetHand());
                break;

            case "Uno":
                if (player.Hand.Count == 1)
                {
                    player.UnoFrag = true;
                }
                else
                {
                    SendData(player, SendParameter.Error, "UnExpectedError");
                }

                break;

            case "DataRequest":
                switch (Content)
                {
                case "OpponentName":
                    SendData(player, SendParameter.OpponentName, opponent.Name);
                    break;

                case "Hand":
                    SendData(player, SendParameter.Hand, player.GetHand());
                    break;

                case "OpponentHand":
                    SendData(player, SendParameter.OpponentHand, opponent.GetOpenedHand());
                    break;

                default:
                    SendData(player, SendParameter.Error, "UnexpectedError");
                    break;
                }
                break;

            default:
                SendData(player, SendParameter.Error, "UnexpectedError");
                break;
            }
        }