Ejemplo n.º 1
0
 // Print a string representing the player, their stats, and their hand.
 public void print()
 {
     Console.Write(String.Format("${0} {1}, ${2}:  ", funds, name, bet));
     foreach (Card card in Hand)
     {
         Console.Write(card.ToString() + " ");
     }
     Console.WriteLine(" : " + BlackjackRules.GetHandValue(this.Hand));
 }
Ejemplo n.º 2
0
        public void print()
        {
            string hiddenCard = (this.downCard ? "## " : "");
            int    startIdx   = (this.downCard ? 1 : 0);

            Console.Write("Dealer:  " + hiddenCard);
            for (int i = startIdx; i < hand.Count; i++)
            {
                Console.Write(hand[i].ToString() + " ");
            }
            if (!this.downCard)
            {
                Console.Write(" : " + BlackjackRules.GetHandValue(this.hand));
            }
            Console.WriteLine();
        }
Ejemplo n.º 3
0
        public override void round()
        {
            newRound();

            // Get bets from all players, deal them cards (secretly)
            foreach (Player player in this.players)
            {
                Console.Clear();
                try {
                    player.AskBet(5, 100);
                }
                catch (FraudException e) {
                    Common.typedPrintln("Security!** Get this idiot outta here!**");
                    UpdateDBWithException(e);
                    player.playing = false;
                    return; // Return from this early.
                }
                dealer.Deal(player, 2);
            }
            dealer.hand.AddRange(dealer.deck.Draw(2));

            Console.Clear();
            Console.WriteLine("Players: ");
            Console.WriteLine();
            showTable();
            Common.WaitEllipses(".", 4000);

            // Check dealer's hand for natural blackjack
            if (BlackjackRules.CheckBlackjack(dealer.hand))
            {
                dealer.downCard = false;
                dealer.print();
                Console.WriteLine("Dealer has a natural blackjack! Any players who can't push lose their bets.");
                Common.Wait(2000);

                // Carry out with the losing of the bets
                foreach (Player player in players)
                {
                    if (BlackjackRules.CheckBlackjack(player.Hand) == false)
                    {
                        player.bet = 0;
                    }
                }
            }
            // Play as normally
            else
            {
                foreach (Player player in players)
                {
                    Console.Clear();
                    Common.WaitEllipses("Grabbing " + player.name, 2000);

                    if (BlackjackRules.CheckBlackjack(player.Hand) == true)
                    {
                        player.won  = true;
                        player.bet += player.bet * 3 / 2;   // Naturals pay 3 to 2, or 150%

                        Console.Clear();
                        player.print();
                        Console.Write("A natural blackjack! You win this round.");
                        Common.Wait(1000);
                    }
                    else
                    {
                        // Allow the player to hit
                        while (player.stay == false && player.busted == false &&
                               BlackjackRules.CheckBlackjack(player.Hand) == false)
                        {
                            Console.Clear();
                            dealer.print();
                            player.print();

                            if (Prompt.GetBool("Hit? [y/n]"))
                            {
                                dealer.Deal(player);
                                if (BlackjackRules.GetHandValue(player.Hand) > 21)
                                {
                                    player.busted = true;
                                }
                            }
                            else
                            {
                                player.stay = true;
                            }
                        }
                        Console.Clear();
                        dealer.print();
                        player.print();
                        Common.WaitEllipses(".", 2000);
                    }
                }

                // The dealer reveals their down card
                Console.Clear();
                dealer.print();
                Common.Wait(1500);
                dealer.downCard = false;
                dealer.print();
                Common.Wait(1500);

                // The dealer plays
                while (BlackjackRules.GetHandValue(dealer.hand) < 17)
                {
                    dealer.hand.Add(dealer.deck.Draw());
                    dealer.print();
                    Common.Wait(1500);
                }

                // Results
                Common.Linebreak();
                showTable();
                Common.WaitEllipses(".", 4000);

                // Round logic
                int dealerValue = BlackjackRules.GetHandValue(dealer.hand);
                int playerValue;
                foreach (Player player in players)
                {
                    playerValue = BlackjackRules.GetHandValue(player.Hand);

                    // Winning: Bet is payed out
                    if (!player.busted &&
                        !player.won &&      // Disqualify them from bet-handling if they had a natural blackjack
                        playerValue > dealerValue)
                    {
                        player.bet *= 2;
                    }
                    // Losing: Lose your bet
                    else if (player.busted ||
                             playerValue < dealerValue)
                    {
                        player.bet = 0;
                    }
                    // Push: You keep your bet
                }
            }
        }