Пример #1
0
 private void btnStart_Click(object sender, RoutedEventArgs e)
 {
     suma                    = 0;
     tallador                = 0;
     jugador                 = 0;
     volo                    = 0;
     btnPedir.Visibility     = Visibility.Visible;
     btnPlantar.Visibility   = Visibility.Visible;
     btnAumentar.Visibility  = Visibility.Hidden;
     btnDisminuir.Visibility = Visibility.Hidden;
     p = new Player();
     d = new Dealer();
     d.Generate();
     d.Randomize();
     p.InitP(d.Deal(), d.Deal());
     d.Init();
     foreach (Card car in p.Hand)
     {
         txtPlayer.Text += car.Symbol + car.Suit + " ";
         suma           += car.Score;
     }
     txtDealer.Text = d.Hand[0].Symbol + d.Hand[0].Suit + " ?";
     if (suma == 21)
     {
         lblResultados.Content = "Blackjack";
         v += 1;
         j += 1;
         btnRestart.Visibility = Visibility.Visible;
         btnPedir.Visibility   = Visibility.Hidden;
         btnPlantar.Visibility = Visibility.Hidden;
         lblDerrotas.Content   = der;
         lblVictorias.Content  = v;
         lblJugadas.Content    = j;
         saldo             += apuesta + apuesta;
         apuesta            = 0;
         lblSaldo.Content   = saldo;
         lblApuesta.Content = apuesta;
     }
     btnStart.Visibility = Visibility.Hidden;
 }
Пример #2
0
        public void StartGame()
        {
            Console.WriteLine("-----------");
            Console.WriteLine("Game start.");

            _challenger.Deal(_deck);
            _challenger.ShowHand();
            _dealer.Deal(_deck);
            _dealer.ShowFirstHand();

            Console.WriteLine("");

            _challenger.Action(_deck);
            if (_challenger.IsBust())
            {
                Console.WriteLine("You Lose");
                return;
            }

            _dealer.Action(_deck);
            Console.WriteLine("");

            Console.WriteLine(Judge());
        }
Пример #3
0
        static void Main(string[] args)
        {
            do
            {
                // Start game
                Console.WriteLine("Welcome to Blackjack!");
                //shuffle deck
                var deck = new Deck();
                deck.Shuffle();
                //deal cards
                var  dealer     = new Dealer();
                Hand playerHand = new Hand();
                Hand compHand   = new Hand();
                //player gets cards
                dealer.Deal(deck, playerHand);
                int playerScore = playerHand.newHand[0].Value + playerHand.newHand[1].Value;
                Console.WriteLine($"Player hand: {playerHand.newHand[0].Suit} {playerHand.newHand[0].Face} {playerHand.newHand[1].Suit} {playerHand.newHand[1].Face}");
                Console.WriteLine($"Player score: {playerScore}");
                //dealer gets cards
                dealer.Deal(deck, compHand);
                int compScore = compHand.newHand[0].Value + compHand.newHand[1].Value;
                Console.WriteLine($"Dealer hand: {compHand.newHand[0].Suit} {compHand.newHand[0].Face} {compHand.newHand[1].Suit} {compHand.newHand[1].Face}");
                Console.WriteLine($"Dealer score: {compScore}");
                Console.WriteLine($"Number of cards left: {deck.cards.Count()}");
                //does everyone have 21? tie game
                if (compScore == 21 && playerScore == 21)
                {
                    Console.WriteLine("Both players have 21! Tie!");
                }
                //does dealer have 21? dealer win
                else if (compScore == 21)
                {
                    Console.WriteLine("Blackjack for the Dealer! 21!");
                }
                //does player have 21? player win
                else if (playerScore == 21)
                {
                    Console.WriteLine("Blackjack for you! 21! You win!");
                }
                else
                {
                    //class Player.Hit(), Stay() if 21 autostay, if score > 21 switch Ace to 1
                    var user = new Player();
                    Console.Write("(H)it or (S)tay: ");
                    string input    = Console.ReadLine();
                    var    userPlay = user.CheckInput(input, deck, playerHand);
                    if (userPlay == true)
                    {
                        Console.WriteLine("Computer turn!");
                        var dealerPlay = dealer.Play(deck, compHand);
                        if (dealerPlay == true)
                        {
                            //resolve scores
                            Console.WriteLine("scores are vs");
                        }
                        else
                        {
                            Console.WriteLine("You win! Dealer busted.");
                        }
                    }
                    else
                    {
                        Console.WriteLine("You busted! Over 21");
                    }

                    Console.Write("Player hand: ");
                    for (int i = 0; i < playerHand.newHand.Count(); i++)
                    {
                        Console.Write($"{playerHand.newHand[i].Suit} {playerHand.newHand[i].Face} ");
                    }
                    Console.WriteLine($"Player score: {playerScore}");
                }

                Console.WriteLine("Play again? y/n");
                restart = Convert.ToChar(Console.ReadLine());
            } while (restart == 'y');
        }