コード例 #1
0
        public void Run()
        {
            hand.Clear();
            MakeNewDeck();

            // Generate hand.
            for (int i = 0; i < CardCount; i++)
            {
                var card = deck[random.Next(deck.Count)];
                deck.Remove(card);
                hand.Add(card);
            }

            DrawCards();

            var parsedNumbers = new List <int>();

            // Read input until correct input is received.
            while (true)
            {
                Console.WriteLine("Enter numbers of hand to discard (space separated): ");

                if (GetInput(parsedNumbers))
                {
                    break;
                }

                Console.WriteLine("Error, invalid input");
            }

            // Shuffle the selected cards.
            foreach (var number in parsedNumbers)
            {
                var card = hand[number];
                hand.Remove(card);
                deck.Add(card);

                card = deck[random.Next(deck.Count)];
                deck.Remove(card);
                hand.Insert(number, card);
            }

            DrawCards();

            var  evaluator     = new HandEvaluator(hand);
            Hand evaluatedHand = evaluator.Evaluate();

            Console.WriteLine("You drew {0} and won {1} coins", evaluatedHand.Name, evaluatedHand.Value);
        }
コード例 #2
0
        public HandValue evaluateHand(Card[] handToEvaluate)
        {
            HandEvaluator handEvaluator = new HandEvaluator(handToEvaluate);

            return(handEvaluator.EvaluateHand());
        }