예제 #1
0
        public List <Card> AskFor(string targetPlayerName, Card targetCard, string senderName)
        {
            hasGameStarted = true;

            if (senderName.ToCapital() == players[1].Item1.ToCapital())
            {
                GameLogs += $"---- {senderName.ToCapital()} is Playing ----\n";
            }

            // find the CallBack info for target player from clientCallBacks
            ICallback targetCb = null;

            List <Card> matchedCards = null;

            foreach (var player_ in players)
            {
                if (player_.Value.Item1.ToLower() == targetPlayerName.ToLower())
                {
                    foreach (var cb_ in clientCallBacks)
                    {
                        if (cb_.Key == player_.Key)
                        {
                            targetCb = cb_.Value;
                        }
                    }
                }
            }

            if (targetCb != null)
            {
                // add message to game log
                GameLogs += $">{senderName.ToCapital()} asks {targetPlayerName.ToCapital()} for {targetCard.Rank.ToString().ToCapital()}s\n";

                matchedCards = targetCb.AskTargetPlayer(targetCard);

                // check if it is time to go fish
                if (matchedCards == null || matchedCards.Count == 0)
                {
                    GameLogs += $">{targetPlayerName.ToCapital()} tells {senderName.ToCapital()} to go fish...\n";
                }
                else
                {
                    GameLogs += $">{targetPlayerName.ToCapital()} gives {senderName.ToCapital()} {matchedCards.Count} {targetCard.Rank.ToString().ToCapital()}(s)\n";
                }

                // the last round
                // EmptyShoe is true && matchedCards is null
                if (EmptyShoe && (matchedCards == null || matchedCards.Count == 0))
                {
                    if (PlayerIdx == clientCallBacks.Count)
                    {
                        // check winner HERE !!!!!!!!!!!!!!!!!!!!
                        CheckWinner();

                        return(matchedCards);
                    }
                    else
                    {
                        PlayerIdx += 1;
                    }
                }

                // update Guis
                updateAllClients();
            }
            else
            {
                Console.WriteLine($"Target player {targetPlayerName.ToCapital()} is not in game room.");
            }

            return(matchedCards);
        }