Пример #1
0
        private void btnPlantar_Click(object sender, RoutedEventArgs e)
        {
            txtDealer.Text = d.Hand[0].Symbol + d.Hand[0].Suit + " " + d.Hand[1].Symbol + d.Hand[1].Suit;
            Check(p.Hand);
            jugador = suma;
            Check(d.Hand);
            tallador = suma;

            while (tallador < jugador && tallador < 21)
            {
                Card nc = d.Deal();
                d.AddCard(nc);
                Check(d.Hand);
                tallador        = suma;
                txtDealer.Text += " " + nc.Symbol + nc.Suit;
            }
            MessageBox.Show("Jugador:" + jugador + "\n Tallador:" + tallador);
            if (tallador == 21 || (tallador > jugador && tallador < 21) || tallador == jugador)
            {
                lblResultados.Content = "Derrota";
                j   += 1;
                der += 1;
                btnRestart.Visibility = Visibility.Visible;
                btnPedir.Visibility   = Visibility.Hidden;
                btnPlantar.Visibility = Visibility.Hidden;
                lblDerrotas.Content   = der;
                lblVictorias.Content  = v;
                lblJugadas.Content    = j;
                apuesta            = 0;
                lblSaldo.Content   = saldo;
                lblApuesta.Content = apuesta;
                if (saldo == 0)
                {
                    btnRestart.Visibility = Visibility.Hidden;
                    MessageBox.Show("Sin saldo");
                    Application.Current.Shutdown();
                }
            }
            else
            {
                if (tallador > 21)
                {
                    lblResultados.Content = "Victoria";
                    j += 1;
                    v += 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;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Starts a new round by assigning variables and instances of classes
        /// </summary>
        public List <Tuple <Card, int[]> > StartRound()
        {
            //Initializing variables
            isRoundPlaying = true;
            deck           = new Deck();

            //Lets store the cards and who it belongs to here
            List <Tuple <Card, int[]> > cardsToReturn = new List <Tuple <Card, int[]> >();

            //Sort all the players
            players = players.OrderBy(p => p.Position).ToList();

            //First deal one card to the dealer...
            Card card = new Card();

            card = deck.FetchCard();
            dealer.AddCard(card);
            cardsToReturn.Add(new Tuple <Card, int[]>(card, new int[] { -1, dealer.AmountOfCards }));

            //...then two cards to all players who has joined
            foreach (Player player in players)
            {
                //Lets bet
                player.Bank -= betLimit;
                player.Bet   = betLimit;

                //First player card
                card = deck.FetchCard();
                player.AddCard(card);
                cardsToReturn.Add(new Tuple <Card, int[]>(card, new int[] { player.Position, player.AmountOfCards }));

                //Second player card
                card = deck.FetchCard();
                player.AddCard(card);
                cardsToReturn.Add(new Tuple <Card, int[]>(card, new int[] { player.Position, player.AmountOfCards }));

                //Check if players score is over 21, then they are out.
                if (player.Score > 21)
                {
                    Console.WriteLine(player.Username + " got busted with " + player.Score);
                    player.Joined = false; //Make sure Joined is set to false

                    //Remove the player from players-list
                    int index = players.FindIndex(x => x.Position == player.Position);
                    bustedPlayers.Add(players[index]); //should be enough to add the player
                }
            }

            //Remove the players who did not make it.
            players.RemoveAll(x => x.Joined == false);
            players.TrimExcess();

            //Lets decide who's gonna start
            if (players.Count > 0)
            {
                players[0].MyTurn = true;
            }

            if (players.Count == 0)
            {
                ResetTable();
            }

            return(cardsToReturn);
        }