public void EndRound()
        {
            while (DealerCards.CardValues()[0] < 16 || DealerCards.CardValues()[1] < 16)
            {
                DealerCards.Add(deck.GetCard());
            }
            foreach (Player player in players)
            {
                DealerUpCards = DealerCards;
                if (player.IsBusted)
                {
                    player.LostBet();
                    continue;
                }
                if (player.HasBlackJack)
                {
                    if (DealerCards.HasBlackJack())
                    {
                        player.Push();
                    }
                    else
                    {
                        player.WonBet(2.5);
                    }
                    continue;
                }
                else
                {
                    if (DealerCards.IsBusted())
                    {
                        player.WonBet(2);
                    }
                    if (player.CardsOnHand.BestBlackJackValue() > DealerCards.BestBlackJackValue())
                    {
                        player.WonBet(2);
                    }
                    else
                    {
                        player.LostBet();
                    }

                    continue;
                }
            }

            deck.GatherCards();
            DealerCards   = new List <Card>();
            DealerUpCards = new List <Card>();
            foreach (Player player in players)
            {
                player.CardsOnHand = new List <Card>();
            }
            players.RemoveAll(plr => plr.IsBankrupt);
        }
Beispiel #2
0
 public void Show()
 {
     Console.WriteLine(@"
     Напишите клиентское консольное приложение для библиотеки  Ch10CardLib,
     позволяющее вытягивать сразу пять карт из перетасованной колоды (объекта Deck).
     Если все пять карт оказываются одной масти, их названия должны быть выведены
     на консоль вместе с текстом Flush!; в противном случае приложение должно
     завершит работу после просмотра 50 карт, с выводом текста No flush.
                     ");
     Deck myDeck = new Deck();
     myDeck.Shuffle();
     List<Card> tempCard = new List<Card>();
     Random genrateNumber = new Random();
     int cardNumber = genrateNumber.Next(52);
     int countFlash = 0;
     for (int i = 5; i <= 50; i += 5)
     {
         tempCard.Clear();
         countFlash = 0;
         for (int j = 0; j < 5; j++)
         {
             tempCard.Add(myDeck.GetCard(j));
             if (tempCard[0].rank == tempCard[j].rank)
             {
                 countFlash += 1;
             }
         }
         if (countFlash == 5)
         {
             Console.WriteLine("Flash! :-)");
             for (int c = 0; c < tempCard.Count; c++)
             {
                 if (i != 5)
                     Console.WriteLine("{0},", tempCard[c].ToString());
                 else
                     Console.WriteLine("{0}\n", tempCard[c].ToString());
             }
         }
         else
         {
             Console.WriteLine("No flash :-(\nYou played {0} times\n", i/5);
         }
     }
     Console.ReadKey();
 }
Beispiel #3
0
        /// <summary>
        /// Parameterized constructor that accepts a Deck object,
        /// shuffled the deck, and stored the collection od cards in the deck
        /// </summary>
        /// <param name="deck"></param>
        public Cards(Deck deck)
        {
            deck.Shuffle(); // shuffle the deck

            int  index   = 0;
            bool isValid = true;

            // Add cards to the list of Playing Cards, while there are cards in the deck
            while (isValid)
            {
                try
                {
                    Add(deck.GetCard(index++));
                }
                catch (Exception ex)
                {
                    isValid = false;
                }
            }
        }