Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using ConsoleCards;
- namespace ProgrammingAssignment3
- {
- class Program
- {
- static void Main(string[] args)
- {
- // HELLO, EVALUTATOR!
- // I added a few things to the code that were not part of the assignment
- // in order to challenge myself. I hope that is ok, and I tried to
- // use proper commenting to make it easier to read.
- //
- // You can also see a PasteBin version of this code (easier to read) at:
- // http://pastebin.com/n8bAcmei
- //
- // - Desmond
- // Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack
- // I added a ReadLine to collect the player's name
- Console.WriteLine("**********************************\n");
- Console.WriteLine("WELCOME!\n\nLet's play a round of blackjack.\nYour hard-earned money is forfeit!\n");
- Console.WriteLine("**********************************\n");
- Console.WriteLine("Type your name and press ENTER to deal...");
- string confirmation = Console.ReadLine();
- // declare variables for and create a deck of cards and blackjack hands for the dealer and player
- // name one BlackjackHand after the player's input
- Deck bicycleRed = new Deck();
- BlackjackHand playerHand = new BlackjackHand(confirmation);
- BlackjackHand dealerHand = new BlackjackHand("Dealer");
- Console.WriteLine();
- // Shuffle the deck of cards
- bicycleRed.Shuffle();
- // Deal 2 cards to the player and dealer
- // Remove the top card, store it into a new card variable, and alternate which deck they go into
- Card card0 = bicycleRed.TakeTopCard();
- dealerHand.AddCard(card0);
- Card card1 = bicycleRed.TakeTopCard();
- playerHand.AddCard(card1);
- Card card2 = bicycleRed.TakeTopCard();
- dealerHand.AddCard(card2);
- Card card3 = bicycleRed.TakeTopCard();
- playerHand.AddCard(card3);
- // 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
- // I also printed the scores (hid the dealer's score) to make it easier to decide if to hit or not
- playerHand.Print();
- Console.WriteLine(confirmation + "'s current score: " + playerHand.Score + "\n");
- dealerHand.Print();
- Console.WriteLine("Dealer's score: ?\n");
- // Let the player hit if they want to
- playerHand.HitOrNot(bicycleRed);
- // Make all the dealer’s cards face up
- dealerHand.ShowAllCards();
- // Print both the player’s hand and the dealer’s hand
- // I added some formatting here
- playerHand.Print();
- Console.WriteLine(confirmation + "'s final score: " + playerHand.Score + "\n\n");
- dealerHand.Print();
- Console.WriteLine("Dealer's final score: " + dealerHand.Score + "\n\n______________\n");
- // Print the scores for both hands
- // I also added conditions so that, based on the score, the appropriate message is printed
- // If blackjack is obtained, the player gets a special message with the unicode character for spade
- if (playerHand.Score > 21)
- {
- Console.WriteLine(confirmation + " LOSES!\n");
- }
- else if (playerHand.Score == 21 && dealerHand.Score != 21)
- {
- Console.WriteLine("\u2660\u2660\u2660f " + "BLACKJACK, you win!" + " \u2660\u2660\u2660\n");
- }
- else if (playerHand.Score > dealerHand.Score && playerHand.Score <= 21)
- {
- Console.WriteLine(confirmation + " WINS!\n");
- }
- else if (playerHand.Score < dealerHand.Score && dealerHand.Score <= 21)
- {
- Console.WriteLine(confirmation + " LOSES!\n");
- }
- else
- {
- Console.WriteLine("Wow ... you both tied!\n");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement