Ejemplo n.º 1
0
        /// <summary>
        /// *********update the form with the status of a hand of cards (bust, blackjack, neither)
        /// </summary>
        public void update_player()
        {
            BlackjackHand hand = game.currentHand;

            highlight(1);

            labels_hand[game.cur_player].Text = hand.Sum.ToString();

            switch (hand.Status)
            {
            case -100:        // BUST (-100)
                update_Hand(" - BUST");
                highlight(0);
                game.gotoNextHand();
                break;

            case 100:        // BLACKJACK (100)
                update_Hand("  - BLACKJACK");
                highlight(0);
                game.gotoNextHand();
                break;

            case 0:        // hand is new
                displayPossibleActions(1);
                break;

            default:                       // hand is not new one
                displayPossibleActions(0); // (stand, hit)
                break;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Hit
        /// </summary>
        /// <param name="HandNum">Player Hand num</param>
        public static void Hit(int HandNum)
        {
            BlackjackHand playerHandNum = PlayerHands[HandNum];

            /*
             * // if the score is atlest 21
             * if (playerHandNum.Score > 21 || playerHandNum.Score == 21) {
             *  // Is standing automaticaly True
             *  playerHandNum.IsStanding = true;
             * } else {
             *  playerHandNum.IsStanding = false;
             * }
             */

            // draw one Card
            playerHandNum.AddCard(_deck.DealOneCard());


            if (playerHandNum.Score > 21 || playerHandNum.Score == 21)
            {
                // Is standing automaticaly True
                playerHandNum.IsStanding = true;
            }
            else
            {
                playerHandNum.IsStanding = false;
            }
        }
        public void Test_BlackjackHand_InitiallyNotStandingOrSurrendered()
        {
            BlackjackHand hand1 = new BlackjackHand();

            Assert.IsFalse(hand1.IsStanding);
            Assert.IsFalse(hand1.HasSurrendered);
        }
        public void Test_BlackjackHand_Score_Example1()
        {
            BlackjackHand hand1 = new BlackjackHand();

            hand1.AddCard(new Card(Suit.Clubs, FaceValue.Two));
            Assert.AreEqual(2, hand1.Score);
        }
        public void Test_BlackjackHand_Score_Example2()
        {
            BlackjackHand hand1 = new BlackjackHand();

            hand1.AddCard(new Card(Suit.Diamonds, FaceValue.Ten));
            Assert.AreEqual(10, hand1.Score);
        }
Ejemplo n.º 6
0
        //methods

        /// <summary>
        /// Reset Everything
        /// </summary>
        public static void Reset()
        {
            DealerHand  = new BlackjackHand();
            PlayerHands = new List <BlackjackHand>();

            PlayerFunds = INITIAL_VALUE;
        }
Ejemplo n.º 7
0
        public BlackjackHandViewModel(BlackjackHand hand)
        {
            IsBlackjack = hand?.IsBlackjack ?? false;
            IsBusted    = hand?.IsBusted ?? false;
            IsSoft      = hand?.IsSoft ?? false;

            Cards = hand?.Cards?.Select(card => new CardViewModel(card))?.ToList()
                    ?? Enumerable.Empty <CardViewModel>();

            if (IsBusted)
            {
                Score = "Busted";
            }
            else if (IsBlackjack)
            {
                Score = "Blackjack";
            }
            else if (IsSoft)
            {
                Score = hand.ScoreHighLow.Item1.ToString();
                if (hand.ScoreHighLow.Item2 <= 21)
                {
                    Score += " or " + hand.ScoreHighLow.Item2.ToString();
                }
            }
            else
            {
                Score = hand == null ? "" : hand.Score.ToString();
            }
        }
        public void Test_BlackjackHand_Constructor_SetsUpBet()
        {
            BlackjackHand hand1 = new BlackjackHand(20);
            BlackjackHand hand2 = new BlackjackHand(40);

            Assert.AreEqual(20, hand1.Bet);
            Assert.AreEqual(40, hand2.Bet);
        }
        public void Test_BlackjackHand_Score_Example9()
        {
            BlackjackHand hand1 = new BlackjackHand();

            hand1.AddCard(new Card(Suit.Diamonds, FaceValue.Ace));
            hand1.AddCard(new Card(Suit.Spades, FaceValue.Ace));
            hand1.AddCard(new Card(Suit.Hearts, FaceValue.Ace));
            Assert.AreEqual(13, hand1.Score);
        }
        public void Test_BlackjackHand_Score_Example6()
        {
            BlackjackHand hand1 = new BlackjackHand();

            hand1.AddCard(new Card(Suit.Diamonds, FaceValue.Ace));
            hand1.AddCard(new Card(Suit.Diamonds, FaceValue.Four));
            hand1.AddCard(new Card(Suit.Diamonds, FaceValue.Seven));
            Assert.AreEqual(12, hand1.Score);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The entire code lives inside the main method
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            /* Declare variables for and create a deck of cards and blackjack hands
             * for the dealer and the player */
            Deck          deck = new Deck();
            BlackjackHand blackjackHandDealer = new BlackjackHand("Dealer");
            BlackjackHand blackjackHandPlayer = new BlackjackHand("Player");

            // The welcome message
            Console.WriteLine("Welcome to the game! The program will play a single hand of Blackjack with you.");
            Console.WriteLine();

            // Shuffle the deck of cards
            deck.Shuffle();

            // Deal 2 cards to the player and dealer
            blackjackHandDealer.AddCard(deck.TakeTopCard());
            blackjackHandDealer.AddCard(deck.TakeTopCard());
            blackjackHandPlayer.AddCard(deck.TakeTopCard());
            blackjackHandPlayer.AddCard(deck.TakeTopCard());

            // Make all the player’s cards face up
            blackjackHandPlayer.ShowAllCards();

            // Make the dealer’s first card face up (the second card is the dealer’s “hole” card)
            blackjackHandDealer.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand
            blackjackHandPlayer.Print();
            blackjackHandDealer.Print();
            Console.WriteLine();

            // Let the player hit if they want to
            blackjackHandPlayer.HitOrNot(deck);
            Console.WriteLine();

            // Make all the dealer’s cards face up; there's a method for this in the BlackjackHand class
            blackjackHandDealer.ShowAllCards();

            // Print both the player’s hand and the dealer’s hand
            blackjackHandPlayer.Print();
            blackjackHandDealer.Print();
            Console.WriteLine();

            // Print the scores for both hands
            int playerScore = blackjackHandPlayer.Score;
            int dealerScore = blackjackHandDealer.Score;

            Console.WriteLine("The player's score is " + playerScore);
            Console.WriteLine("The dealer's score is " + dealerScore);
            Console.WriteLine();
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Check if Can Stand
        /// </summary>
        /// <param name="HandNum">PLayer Hand num</param>
        /// <returns>Return True if player Can Stand</returns>
        public static bool CanStand(int HandNum)
        {
            BlackjackHand playerHandNum = PlayerHands[HandNum];

            if (playerHandNum.Score <= 20 && playerHandNum.IsStanding == false)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        ///  display final result of given hand
        /// </summary>
        /// <param name="player_id"></param>
        /// <param name="hand"></param>
        public void displayFinalResult(int player_id, BlackjackHand hand)
        {
            labels_hand[player_id].Text = hand.Sum + " - " + hand.result.ToString();

            if (hand.result == BlackjackHand.Result.WIN)
            {
                labels_hand[player_id].ForeColor = System.Drawing.Color.GreenYellow;
            }
            else
            {
                labels_hand[player_id].ForeColor = System.Drawing.Color.White;
            }
        }
Ejemplo n.º 14
0
        /// <summary> 
        /// A single hand of Blackjack
        /// </summary> 
        /// <param name="args">command-line args</param> 
        static void Main(string[] args)
        {
            //Declare variables for and create a deck of cards and blackjack hands for the dealer and the player

            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack

            Console.WriteLine("You will play a single hand of Blackjack.");

            // Shuffle the deck of cards

            deck.Shuffle();

            //Deal 2 cards to the player and dealer
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //Show all the player’s cards

            playerHand.ShowAllCards();

            //Show the dealer’s first card

            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Let the player hit if they want to

            playerHand.HitOrNot(deck);

            //Show all the dealer’s cards

            dealerHand.ShowAllCards();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Print the scores for both hands

            Console.WriteLine("Player's score: " + playerHand.Score + ".");
            Console.WriteLine("Dealer's score: " + dealerHand.Score + ".");
        }
Ejemplo n.º 15
0
        /// <summary>
        /// A single hand of Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            //Declare variables for and create a deck of cards and blackjack hands for the dealer and the player

            Deck          deck       = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack

            Console.WriteLine("You will play a single hand of Blackjack.");

            // Shuffle the deck of cards

            deck.Shuffle();

            //Deal 2 cards to the player and dealer
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //Show all the player’s cards

            playerHand.ShowAllCards();

            //Show the dealer’s first card

            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Let the player hit if they want to

            playerHand.HitOrNot(deck);

            //Show all the dealer’s cards

            dealerHand.ShowAllCards();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Print the scores for both hands

            Console.WriteLine("Player's score: " + playerHand.Score + ".");
            Console.WriteLine("Dealer's score: " + dealerHand.Score + ".");
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Check if Can Double
        /// </summary>
        /// <param name="HandNum">Player Hand num</param>
        /// <returns>Return True if Can Double</returns>
        public static bool CanDouble(int HandNum)
        {
            BlackjackHand playerHandNum = PlayerHands[HandNum];


            if (playerHandNum.Score <= 20 && playerHandNum.IsStanding == false &&
                playerHandNum.HasSurrendered == false && PlayerFunds >= playerHandNum.Bet)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Double
        /// </summary>
        /// <param name="HandNum">Player Hand num</param>
        public static void Double(int HandNum)
        {
            BlackjackHand playerHandNum = PlayerHands[HandNum];

            //automatic standing
            playerHandNum.IsStanding = true;

            // add one card to hand
            playerHandNum.AddCard(_deck.DealOneCard());

            // substract fund
            PlayerFunds -= playerHandNum.Bet;

            // double the bet
            playerHandNum.Bet += playerHandNum.Bet;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Check if Can Hit
        /// </summary>
        /// <param name="HandNum">Player Hand num</param>
        /// <returns>Return True if Can Hit</returns>
        public static bool CanHit(int HandNum)
        {
            //BlackjackHand playerZero = PlayerHands[0];
            //BlackjackHand playerOne = PlayerHands[1];
            //BlackjackHand playerTwo = PlayerHands[2];

            BlackjackHand playerHandNum = PlayerHands[HandNum];

            if (playerHandNum.Score <= 20 && playerHandNum.IsStanding == false)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Let you play a hand of Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            //create deck and two hands
            Deck          deck       = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //print welcome message
            Console.WriteLine("Welcome friend!");
            Console.WriteLine("You are now going to play a single hand of Blackjack\n");

            //shuffle the deck
            deck.Shuffle();

            //deal two cards for player
            playerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //deal two cards for dealer
            dealerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            //make all player's cards face up
            playerHand.ShowAllCards();

            //make first dealer's card face up
            dealerHand.ShowFirstCard();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //ask player if he wants to "hit"
            playerHand.HitOrNot(deck);

            //make all dealer's card face up
            dealerHand.ShowAllCards();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //print scores
            Console.WriteLine("Player score: {0}", playerHand.Score);
            Console.WriteLine("Dealer score: {0}", dealerHand.Score);
        }
        /// <summary>
        /// Let you play a hand of Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            //create deck and two hands
            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //print welcome message
            Console.WriteLine("Welcome friend!");
            Console.WriteLine("You are now going to play a single hand of Blackjack\n");

            //shuffle the deck
            deck.Shuffle();

            //deal two cards for player
            playerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //deal two cards for dealer
            dealerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            //make all player's cards face up
            playerHand.ShowAllCards();

            //make first dealer's card face up
            dealerHand.ShowFirstCard();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //ask player if he wants to "hit"
            playerHand.HitOrNot(deck);

            //make all dealer's card face up
            dealerHand.ShowAllCards();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //print scores
            Console.WriteLine("Player score: {0}", playerHand.Score);
            Console.WriteLine("Dealer score: {0}", dealerHand.Score);
        }
        public void Test_BlackjackHand_Score_Example3()
        {
            BlackjackHand hand1 = new BlackjackHand();

            hand1.AddCard(new Card(Suit.Clubs, FaceValue.Jack));

            BlackjackHand hand2 = new BlackjackHand();

            hand2.AddCard(new Card(Suit.Hearts, FaceValue.Queen));

            BlackjackHand hand3 = new BlackjackHand();

            hand3.AddCard(new Card(Suit.Spades, FaceValue.King));

            Assert.AreEqual(10, hand1.Score);
            Assert.AreEqual(10, hand2.Score);
            Assert.AreEqual(10, hand3.Score);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// Check if Can Surrender
        /// </summary>
        /// <returns>Return true if player can Surrender</returns>
        public static bool CanSurrender()
        {
            if (PlayerHands.Count == 1)
            {
                BlackjackHand playerHandNum = PlayerHands[0];

                if (playerHandNum.Score <= 20 && playerHandNum.IsStanding == false)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 23
0
        static void Main(string[] args)
        {
            BlackjackHand   Hand   = new BlackjackHand();
            BlackjackDealer Dealer = new BlackjackDealer();
            BlackjackPlayer Player = new BlackjackPlayer(Hand, 500, "Player 1");

            BlackjackModel      Model      = new BlackjackModel(Dealer, Player);
            BlackjackController Controller = new BlackjackController(Model);

            //  >>>>>[  To use the straight Console/CLI View
            //          -----
            //          BlackjackConsoleView View = new BlackjackConsoleView(Model, Controller);

            //  >>>>>[  To use the "Fake-Curses" View
            //          -----
            BlackjackCursesView View = new BlackjackCursesView(Model, Controller);

            Model.LinkView(View);
            View.ModelChanged();
        }
Ejemplo n.º 24
0
        public void TestBlackjackHand()
        {
            Card jackOfClubs   = new Card(SuitEnum.Clubs, SymbolEnum.Jack);
            Card aceOfSpades   = new Card(SuitEnum.Spades, SymbolEnum.Ace);
            Card aceOfHearts   = new Card(SuitEnum.Hearts, SymbolEnum.Ace);
            Card eightOfHearts = new Card(SuitEnum.Hearts, SymbolEnum.Eight);
            Card nineOfHearts  = new Card(SuitEnum.Hearts, SymbolEnum.Nine);

            BlackjackHand hand =
                new BlackjackHand(new Card[] { jackOfClubs, aceOfSpades, eightOfHearts });

            Assert.IsTrue(
                hand.Cards.Count == 3,
                "Should be 3 cards.");

            BlackjackHand hand2 =
                new BlackjackHand(new Card[] { jackOfClubs, aceOfSpades, eightOfHearts });

            Assert.IsTrue(
                hand.Equals(hand2),
                "Hands are equal.");

            hand2 = new BlackjackHand(new Card[] { jackOfClubs, aceOfSpades, nineOfHearts });

            Assert.IsTrue(
                false == hand.Equals(hand2),
                "Hands are not equal.");

            Assert.IsTrue(
                hand.Value == 19,
                "Blackjack hand value is 19");

            hand = new BlackjackHand(new Card[] { jackOfClubs, aceOfSpades, eightOfHearts, aceOfHearts });
            Assert.IsTrue(
                hand.Value == 20,
                "Blackjack hand value is 20");


            TestContext.WriteLine(hand.ToString());
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Check if Can Split
        /// </summary>
        /// <returns>Return True if player Can split</returns>
        public static bool CanSplit()
        {
            BlackjackHand playerHandNum = PlayerHands[0];

            if (PlayerHands[0].Count <= 2 && !playerHandNum.IsStanding)
            {
                if ((playerHandNum.GetCard(0).FaceValue == playerHandNum.GetCard(1).FaceValue) ||
                    ((int)playerHandNum.GetCard(0).FaceValue >= 10 && (int)playerHandNum.GetCard(1).FaceValue >= 10) &&
                    playerHandNum.IsStanding == false)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 26
0
        /// <summary>
        /// make a new round
        /// </summary>
        /// <param name="initialBet"> The bet </param>
        public static void NewRound(int initialBet)
        {
            // make a full deck and shuffle it
            _deck = new CardPile(true);
            _deck.ShufflePile();

            // reduce the player fund
            PlayerFunds -= initialBet;


            DealerHand = new BlackjackHand();

            // make a new player hand
            PlayerHands = new List <BlackjackHand>();
            PlayerHands.Add(new BlackjackHand(initialBet));


            // deals  2 card to the player and the dealer
            for (int i = 0; i < 2; i++)
            {
                PlayerHands[0].AddCard(_deck.DealOneCard());
                DealerHand.AddCard(_deck.DealOneCard());
            }
        }
        public void BlackjackTest(int _)
        {
            // Arrange new deck
            var cards = new List <BlackjackCard>(52);

            for (int suit = 0; suit < 4; suit++)
            {
                for (int value = 1; value <= 13; value++)
                {
                    cards.Add(new BlackjackCard((CardSuit)suit, value));
                }
            }
            var deck = new Deck <BlackjackCard>(cards);

            // Assert new deck
            Assert.AreEqual(52, deck.TotalCards, "Incorrect total number of cards in the initial deck.");
            Assert.AreEqual(52, deck.RemainingCards, "Incorrect remaining number of cards in the initial deck.");
            Assert.IsTrue(cards.SequenceEqual(deck.Cards));

            // Act 1
            deck.Shuffle();
            List <BlackjackCard> handOfCards = deck.DealHand(2);
            var hand = new BlackjackHand(handOfCards);

            // Assert new hand
            Assert.AreEqual(52, deck.TotalCards, "Incorrect total number of cards in the deck.");
            Assert.AreEqual(50, deck.RemainingCards, "Incorrect remaining number of cards in the deck.");
            Assert.IsTrue(handOfCards.SequenceEqual(hand.Cards));

            int expectedScore = handOfCards[0].MaxValue + handOfCards[1].MaxValue;

            if (handOfCards[0].IsAce && handOfCards[1].IsAce)
            {
                expectedScore = 12;
            }
            Console.WriteLine($"Initial Score: {hand.Score()}. Cards in hand: {hand}");

            Assert.AreEqual(expectedScore, hand.Score(), "Incorrect score calculated.");
            Assert.AreEqual(expectedScore > 21, hand.IsBusted, "Check IsBusted failed.");
            Assert.AreEqual(expectedScore == 21, hand.Is21, "Check Is21 failed.");
            Assert.AreEqual(expectedScore == 21, hand.IsBlackjack, "Check IsBlackjack failed.");

            // Act 2
            int count = 1;

            while (!hand.IsBusted && !hand.Is21)
            {
                BlackjackCard newCard = deck.DealCard();
                hand.AddCard(newCard);
                handOfCards.Add(newCard);

                // Assert updated hand
                Assert.AreEqual(52, deck.TotalCards, "Incorrect total number of cards in the deck.");
                Assert.AreEqual(50 - count, deck.RemainingCards, "Incorrect remaining number of cards in the deck.");
                Assert.IsTrue(handOfCards.SequenceEqual(hand.Cards));

                int  expectedMinScore = 0;
                int  expectedMaxScore = 0;
                bool aceFound         = false;
                foreach (BlackjackCard card in handOfCards)
                {
                    if (!aceFound && card.IsAce)
                    {
                        expectedMaxScore += card.MaxValue;
                        aceFound          = true;
                    }
                    else
                    {
                        expectedMaxScore += card.Value;
                    }
                    expectedMinScore += card.Value;
                }
                expectedScore = expectedMaxScore > 21 ? expectedMinScore : expectedMaxScore;
                Console.WriteLine($"Round {count} Score: {hand.Score()}. Cards in hand: {hand}");

                Assert.AreEqual(expectedScore, hand.Score(), "Incorrect score calculated.");
                Assert.AreEqual(expectedScore > 21, hand.IsBusted, "Check IsBusted failed.");
                Assert.AreEqual(expectedScore == 21, hand.Is21, "Check Is21 failed.");
                Assert.IsFalse(hand.IsBlackjack, "Check IsBlackjack failed.");

                count++;
            }

            // Act 3
            deck.ResetDeck();

            // Assert after deck reset
            Assert.AreEqual(52, deck.TotalCards, "Incorrect total number of cards after deck reset.");
            Assert.AreEqual(52, deck.RemainingCards, "Incorrect remaining number of cards after deck reset.");
        }
Ejemplo n.º 28
0
        static void Main(string[] args)
        {
            //Declare variables for and create a deck of cards and blackjack hands for the dealer and the player
            // create a new deck
            Console.WriteLine("----- A New deck Shuffled-----");
            Deck deck = new Deck();

            //only for check:
            //deck.Print();
            Console.WriteLine();

            //blackjack hands for the dealer
            BlackjackHand dealerHand = new BlackjackHand("dealer");

            //blackjack hands for the player
            BlackjackHand playerHand = new BlackjackHand("player");

            // Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack
            Console.WriteLine("Welcome. This program will play a single hand of Blackjack");

            Console.WriteLine();

            // suffle the deck
            deck.Shuffle();

            //Take top card from deck
            Card drawCard = deck.TakeTopCard();

            //drawCard.FlipOver();
            //Console.WriteLine(drawCard.Rank + " of " + drawCard.Suit);
            // Deal 2 cards to the player and dealer
            // add card to dealer hand
            dealerHand.AddCard(drawCard);
            //Take top card from deck & add to player hand
            drawCard = deck.TakeTopCard();
            playerHand.AddCard(drawCard);
            //Take top card from deck & add to dealer hand
            drawCard = deck.TakeTopCard();
            dealerHand.AddCard(drawCard);
            //Take top card from deck & add to player hand
            drawCard = deck.TakeTopCard();
            playerHand.AddCard(drawCard);

            //Make all the player’s cards face up
            playerHand.ShowAllCards();

            //Make the dealer’s first card face up
            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand
            playerHand.Print();
            dealerHand.Print();

            //Ask player if they want to stay or hit
            playerHand.HitOrNot(deck);
            //Print player’s hand
            playerHand.Print();

            //Make the dealer’s all cards face up and print
            dealerHand.ShowAllCards();
            dealerHand.Print();

            //print scores
            Console.WriteLine("---- Score ----");
            Console.WriteLine("Player: " + playerHand.Score + " Dealer: " + dealerHand.Score);

            Console.WriteLine();
        }
 public void Test_BlackjackHand_Constructor_RunsWithoutErrors()
 {
     BlackjackHand hand1 = new BlackjackHand();
     BlackjackHand hand2 = new BlackjackHand(10);
 }
Ejemplo n.º 30
0
        static bool PlayBlackjack()
        {
            var deck = new Deck();

            deck.Shuffle();

            var dealerHand = new BlackjackHand();
            var userHand   = new BlackjackHand();

            dealerHand.AddCard(deck.DealCard());
            dealerHand.AddCard(deck.DealCard());
            Console.WriteLine("\nDealer's face card is " + dealerHand.GetCard(0));

            userHand.AddCard(deck.DealCard());
            userHand.AddCard(deck.DealCard());
            Console.Write("\nUser has" + " " + userHand.GetBlackjackValue() + "\n");
            userHand.DisplayCards();

            if (userHand.GetBlackjackValue() == 21)
            {
                Console.WriteLine("\nCongratulations you win!");
                userHand.Clear();
                return(true);
            }
            else if (dealerHand.GetBlackjackValue() == 21)
            {
                Console.WriteLine("\n You Lose");
                userHand.Clear();
                return(false);
            }

            while (true)
            {
                if (userHand.GetBlackjackValue() < 21)
                {
                    int choice = GetChoice();
                    switch (choice)
                    {
                    case 1:
                    {
                        userHand.AddCard(deck.DealCard());
                        userHand.DisplayCards();
                        break;
                    }

                    case 2:
                    {
                        Console.Write("\n" + userHand.GetBlackjackValue());
                        break;
                    }

                    default:
                    {
                        Console.WriteLine("Please enter a valid choice");
                        break;
                    }
                    }
                }
                else
                {
                    Console.WriteLine("You lose!");
                    Console.WriteLine(dealerHand.GetBlackjackValue());
                    return(false);
                }
                // Console.WriteLine("\nDealer has " + dealerHand.GetBlackjackValue() + "/21");
                while (dealerHand.GetBlackjackValue() <= 16)
                {
                    dealerHand.AddCard(deck.DealCard());
                    // Console.Write("\nDealer has" + " " + dealerHand.GetCardCount() + " ");

                    if (dealerHand.GetBlackjackValue() > 21)
                    {
                        Console.WriteLine("\nDealer busts... User wins!");
                        Console.WriteLine("\nDealer has " + dealerHand.GetBlackjackValue() + "/21");
                        return(true);
                    }
                    else if (dealerHand.GetBlackjackValue() >= userHand.GetBlackjackValue())
                    {
                        Console.WriteLine("\nDealer Wins!");
                        Console.WriteLine("\nDealer has " + dealerHand.GetBlackjackValue() + "/21");
                        return(false);
                    }
                    else if (userHand.GetBlackjackValue() >= dealerHand.GetBlackjackValue())
                    {
                        Console.WriteLine("\nUser wins!");
                        Console.WriteLine("\nDealer has " + dealerHand.GetBlackjackValue() + "/21");
                        return(true);
                    }
                }
            }
        }
Ejemplo n.º 31
0
 public BlackjackDealer(BlackjackHand hand)
 {
     Hand = hand;
 }
Ejemplo n.º 32
0
 public BlackjackDealer()
 {
     Hand = new BlackjackHand();
 }