Ejemplo n.º 1
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.º 2
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.º 3
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 + ".");
        }
        /// <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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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();
        }
Ejemplo n.º 7
0
        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 playerHand = new BlackjackHand("Player");
            BlackjackHand dealerHand = new BlackjackHand("Dealer");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack
            Console.WriteLine("Hi Player, let's play one hand of BlackJack.");

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

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

            //Make all the player’s cards face up (you need to see what you have!); there's a method for this in the BlackjackHand class
            playerHand.ShowAllCards();

            //Make the dealer’s first card face up (the second card is the dealer’s “hole” card); there's a method for this in the BlackjackHand class
            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand
            Console.Write("Player: ");
            playerHand.Print();
            Console.Write("Dealer: ");
            dealerHand.Print();

            //Let the player hit if they want to
            playerHand.HitOrNot(deck);

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

            //Print both the player’s hand and the dealer’s hand
            Console.Write("Player: ");
            playerHand.Print();
            Console.Write("Dealer: ");
            dealerHand.Print();

            //Print the scores for both hands
            Console.WriteLine("Player score: " + playerHand.Score);
            Console.WriteLine("Dealer score: " + dealerHand.Score);
            Console.WriteLine();

            //Print win message
            if (playerHand.Score <= 21 &&
                playerHand.Score > dealerHand.Score)
            {
                Console.WriteLine("Yahooooo!!! Player won!");
            }
            else if (dealerHand.Score <= 21 &&
                     playerHand.Score < dealerHand.Score)
            {
                Console.WriteLine("Dealer won the game :(");
            }
            else
            {
                Console.WriteLine("Draw.");
            }

            //Print blank line
            Console.WriteLine();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Blackjack game in console
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Declare varables for and create a deck of cards and blackjack hands for the dealer and the player
            Deck          deck0      = new Deck();
            BlackjackHand playerHand = new BlackjackHand("Player");
            BlackjackHand dealerHand = new BlackjackHand("Dealer");

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

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

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

            // Make all the player’s cards face up (you need to see what you have!); there's a method for this in the BlackjackHand class
            playerHand.ShowAllCards();

            //Make the dealer’s first card face up (the second card is the dealer’s “hole” card); there's a method for this in the BlackjackHand class
            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(deck0);

            //(ignore this) experimental code - looping invalid input (I only realised there's a HitOrNot meathod for this after wasting the time)
            ConsoleKeyInfo key;
            int            i = 1;

            while (i == 1)
            {
                i--;
                if (key.Key == ConsoleKey.Enter)
                {
                    Console.Write("\nDo you want to hit? (y/n):");
                    key = Console.ReadKey();
                    i++;
                }
                else
                {
                    if (key.Key == ConsoleKey.Y)
                    {
                        Console.WriteLine("\nyes");
                    }
                    else if (key.Key == ConsoleKey.N)
                    {
                        Console.WriteLine("\nno");
                    }
                    else
                    {
                        Console.Write("\nDo you want to hit? (y/n):");
                        key = Console.ReadKey();
                        i++;
                    }
                }
            }

            //Make all the dealer’s cards face up; there's a method for this in the BlackjackHand class
            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("Your score is:" + playerHand.Score);
            Console.WriteLine("The dealer's score is:" + dealerHand.Score);

            //(Ignore this) Calculate who won
            if (playerHand.Score == 21)
            {
                Console.WriteLine("Blackjack! You won!");
            }
            else if (playerHand.Score > 21 || playerHand.Score < dealerHand.Score)
            {
                Console.WriteLine("You lost!");
            }
            else if (playerHand.Score == dealerHand.Score)
            {
                Console.WriteLine("Push!");
            }
            else
            {
                Console.WriteLine("You won!");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Console application that plays Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>

        static void Main(string[] args)
        {
            // Create a deck of cards
            Deck deck = new Deck();

            // Create blackjack hands for the dealer and the player
            BlackjackHand playerHand = new BlackjackHand("Player");
            BlackjackHand dealerHand = new BlackjackHand("Dealer");

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

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

            // Deal 2 cards to the player and dealer
            // Otherwise
            // Card card; // Create a card
            // card = deck.TakeTopCard();
            // playerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // playerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // dealerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // dealerHand.AddCard(card);
            playerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            // 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();

            // Let the player hit if they want to
            // Otherwhise
            // Console.Write("Hit or stand? (h or s): ");
            // char answer = Console.ReadLine()[0];
            // Console.WriteLine();
            //
            // if (answer == 'h')
            // {
            //     card = deck.TakeTopCard();
            //     playerHand.AddCard(card);
            //     playerHand.ShowAllCards();
            // }
            playerHand.HitOrNot(deck);

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

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

            // Print the scores for both hands
            // Otherwhise
            // int playerScore = playerHand.Score;
            // Console.WriteLine("The player score is: " + playerScore);
            // int dealerScore = dealerHand.Score;
            // Console.WriteLine("The dealer score is: " + dealerScore);
            Console.WriteLine("The player score is: " + playerHand.Score);
            Console.WriteLine("The dealer score is: " + dealerHand.Score);
            Console.WriteLine();

            Console.ReadKey();
        }