Esempio n. 1
0
    /// <summary>
    /// validate the cards in Players' hands
    /// </summary>
    /// <param name="hand"></param>
    /// <returns></returns>
    public static bool Validate_Input_Hand(string hand)
    {
        // proper length of input (+1 to account for space between hands)
        int inputLength = NumberOfCardsPerHand * NumberOfPlayers * 2 + 1;

        string[] hands;

        // check size of hand
        if (hand.Length > inputLength || hand.Length < inputLength)
        {
            ErrorHand = "Please input two hands seperated by a space.";
            return(false);
        }

        // split cards into two hands
        hands = hand.Split(' ');

        // verify each hand contains valid cards and add them to the player's hand
        for (int i = 0; i < NumberOfPlayers; ++i)
        {
            // find player
            int handNum = i + 1;
            Players.TryGetValue(PlayerName + handNum, out Player player);

            // check contents of hand
            for (int j = 0; j < NumberOfCardsPerHand * 2; ++j)
            {
                Deck.Card checkCard = new Deck.Card(hands[i][j], hands[i][++j]);
                //checkCard.value = hands[i][j];
                //checkCard.suit = hands[i][++j];
                if (!CardDeck.FullDeck.Contains(checkCard))
                {
                    // clear each player's hand (in-case user changes previous players' cards)
                    foreach (var _player in Players)
                    {
                        _player.Value.Hand.Clear();
                    }

                    ErrorHand = "Invalid characters for card detected: " + checkCard.value + checkCard.suit;
                    return(false);
                }

                // add card to player's hand
                player.Hand.Add(checkCard);
            }
        }

        // TODO: check for duplicates

        return(true);
    }
Esempio n. 2
0
 /// <summary>
 /// helper function for Order_Hands(): swaps two Cards in a List
 /// </summary>
 /// <param name="hand"></param>
 /// <param name="index1"></param>
 /// <param name="index2"></param>
 private static void Swap(List <Deck.Card> hand, int index1, int index2)
 {
     Deck.Card temp = hand[index1];
     hand[index1] = hand[index2];
     hand[index2] = temp;
 }