Exemplo n.º 1
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            btnSave.Visibility = Visibility.Hidden;
            btnCard.Visibility = Visibility.Hidden;
            int pointsPlayer = p.Check(p.Hand);
            int pointsDealer = d.Check(d.Hand);

            if (pointsDealer > pointsPlayer && pointsDealer > 16)
            {
                txtResultsDealer.Text = "";
                foreach (Card c in d.Hand)
                {
                    txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                }
                MessageBox.Show("Dealer win");
                defeat += 1;
            }
            else
            {
                while (pointsDealer < pointsPlayer)
                {
                    d.Confirm(d.Deck);
                    Card j = d.Deal();
                    d.AddCard(j);
                    txtResultsDealer.Text = "";
                    pointsDealer         += j.Score;

                    if (pointsDealer > 21)
                    {
                        foreach (Card i in d.Hand)
                        {
                            txtResultsDealer.Text += i.Symbol + i.Suit + "  ";
                            if (i.Symbol == "A")
                            {
                                i.Score = 1;
                            }
                        }
                    }
                    pointsDealer = d.Check(d.Hand);
                    if (pointsDealer > 21)
                    {
                        MessageBox.Show("You win");
                        victories += 1;
                    }
                }
                while (pointsDealer < 17)
                {
                    d.Confirm(d.Deck);
                    Card z = d.Deal();
                    d.AddCard(z);
                    txtResultsDealer.Text = "";
                    pointsDealer         += z.Score;
                    foreach (Card c in d.Hand)
                    {
                        txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                        if (pointsDealer > 21)
                        {
                            foreach (Card i in d.Hand)
                            {
                                if (i.Symbol == "A")
                                {
                                    i.Score = 1;
                                }
                            }
                        }
                    }
                    pointsDealer = d.Check(d.Hand);
                    if (pointsDealer > 21)
                    {
                        MessageBox.Show("You win");
                        victories += 1;
                    }
                }
                if (pointsDealer < 22)
                {
                    txtResultsDealer.Text = "";
                    foreach (Card c in d.Hand)
                    {
                        txtResultsDealer.Text += c.Symbol + c.Suit + "  ";
                    }
                    if (pointsDealer == pointsPlayer)
                    {
                        MessageBox.Show("Tie");
                        tie += 1;
                    }
                    else
                    {
                        MessageBox.Show("You lose");
                        defeat += 1;
                    }
                }
            }
            btnNewGame.Visibility = Visibility.Visible;
            btnFinish.Visibility  = Visibility.Visible;
        }