コード例 #1
0
        protected override void IsWinner()
        {
            Card pickedCard = null;
            string hintMessage;
            int guesses = int.Parse(lblGuesses.Text);
            int sumOfPickedCard = 0;
            _guessTheCard = new GuessTheCard(_mysteryCard);

            foreach (Card guessCard in _deckToPick)
            {
                if (cbPickDeck.SelectedItem != null)
                {
                    if (cbPickDeck.SelectedItem.ToString() == guessCard.ToString())
                    {
                        hintMessage = _guessTheCard.CardHints(guessCard);
                        lblHint.Text = hintMessage;
                        pickedCard = _guessTheCard.GuessCard(guessCard);
                        sumOfPickedCard = _guessTheCard.GetSumOfCards();
                    }
                }
            }
            if (_guessTheCard.IsWinner(sumOfPickedCard))
            {
                lblMysteryCard.Text = _mysteryCard.ToString();
                DialogResult result = MessageBox.Show("You are a winner! \nWould you like to play again?",
                                                      "Guess The Card Result",
                                                      MessageBoxButtons.YesNo);
                switch (result)
                {
                    case DialogResult.Yes: StartGame();
                        break;
                    case DialogResult.No: Close();
                        break;
                }
            }
            else if (guesses == 4)
            {
                lblGuesses.Text = "5";
                lblMysteryCard.Text = _mysteryCard.ToString();
                DialogResult result = MessageBox.Show("You are a loser! \nWould you like to play again?",
                                                      "Guess The Card Result",
                                                      MessageBoxButtons.YesNo);
                switch (result)
                {
                    case DialogResult.Yes: StartGame();
                        break;
                    case DialogResult.No: Close();
                        break;
                }

            }
            else
            {
                _deckToPick.Discard(pickedCard);
                ShowCards();

                guesses++;
                lblGuesses.Text = guesses.ToString();
            }
        }
コード例 #2
0
        public void GetCardSum()
        {
            Card mysteryCard = new Card(Rank.Two, Suit.Spades);
            Card pickedCard = new Card(Rank.Two, Suit.Spades);
            GuessTheCard guessTheCard = new GuessTheCard(mysteryCard);
            guessTheCard.GuessCard(pickedCard);
            int pickedCardSum = guessTheCard.GetSumOfCards();

            Assert.AreEqual(true, guessTheCard.IsWinner(pickedCardSum));
        }