You are going to create the classes and menu for the Blackjack project.
There will be 2 parts to Lab:
Part A-1: Setup
You will need to create 2 projects for your part A:
Create the classes, interface and enums in the class library.
The menu can be handled in the console application.
Part A-2: enums
Create 2 enums to represent the data for a Suit and Face.
CardSuit: Spades, Hearts, Clubs, Diamonds
CardFace: A, 2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K
Part A-3: ICard
Create an interface to represent the public interface for a Card.
Add the following properties to the interface: Face, Suit. ONLY have a get - do not put a set on the properties. Use the enums for the Face and Suit.
Add a Draw method. It should not return anything but take 2 int parameters: x and y. NOTE: interfaces cannot have any code.
Part A-4: The Card Class
Create a Card class. Implement the ICard interface. The properties should have private setters.
Add a constructor to the Card class that takes 2 parameters for face and suit. Also add a Draw method that will draw the card starting at the specified x,y position in the console window.
PROPERTIES
NAME | TYPE | COMMENTS |
Suit | CardSuit | Make the setter private |
Face | CardFace | Make the setter private |
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
Card | face, suit | A parameterized constructor for the Card class. Set the properties of the class to the values passed in the parameters. | |
Draw | void | x,y | Draws the card starting at the x,y position in the console. |
Part A-4: The Card Factory class
Create a static Factory class that will have a static method for creating cards.
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
CreateCard | ICard | face, suit | A static method that creates a Card instance using the parameters and returns it. |
USAGE EXAMPLE
ICard card = Factory.CreateCard(CardFace.Ace, CardSuit.Hearts);
Part A-5: The Deck Class
You can't play a card game without a deck of cards, so youll want to add a Deck class. The Deck class has data (list of cards) and behavior (Shuffle, Draw).
The constructor for the Deck class should generate all 52 cards (4 suits * 13 cards per suit). You can do it in the constructor or call a method that creates the cards. Call the Card Factory to create the card instances.
Shuffle should reorder the cards in the list to mimic real-life shuffling.
Deal should return 1 card from the top of the deck. You'll need to consider what to do when the deck is empty. The dealer will use the Draw method to get a card from the deck and add it to the players / dealers hand.
FIELDS
NAME | TYPE | COMMENTS |
_cards | List< ICard> | Initialize in the constructor or in the declaration |
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
Deck | (none) | Initializes the list of cards. | |
Deal | ICard | (none) | Returns a card from the list of cards. Recreate the deck if the list of cards is empty. |
Shuffle | void | (none) | Reorders the cards in the list to mimic real-life shuffling |
Part A-6: The Hand Class
You'll want a Hand class to hold the cards for a player or dealer. Each player is dealt cards. Those cards that the player has is consider the players Hand. A Hand class can have data (list of cards) and behavior (AddCard).
AddCard should take a card as a parameter and add it to the list of cards for the Hand.
Draw should take x,y parameters. They will serve as the starting top-left coordinates for where to start drawing the cards. The Draw method should draw the cards horizontally meaning that the starting y position for each card would be the same but the starting x position of each card will be different.
FIELDS
NAME | TYPE | COMMENTS |
_cards | List< ICard> | Initialize in the constructor or in the declaration. Make this field protected. |
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
AddCard | void | ICard | Adds the card to the list of cards |
Draw | void | x, y | Calls the Draw method of each card in _cards. Draw the cards horizontally, the y would be the same for each card but the x would change. |
Part A-7: The Menu
Add a menu loop to the Main method in Program.cs of your Console application. Your game's main menu should give them 3 options: Play Blackjack, Shuffle & Show Deck, Exit.
Part A-8: Card appearance
Using the functions of the Console class, come up with a way of representing the cards as more than just a number and a single character for the suit. What about writing a white box to the screen, with red or black letters depending on the suit?
The minimum should be a different background color for the card (white?), a symbol for the suit and the card face.
For Part B, you will add new classes that inherit from the classes in Part A. These classes provided specialized behavior for the Blackjack game.
Part B-1: BlackjackCard class
Create a BlackjackCard class that derives from the Card class from Part A. Add a Value property.
Value is the Blackjack value of the card: K = 10, Q = 10, J = 10, 10 = 10, 9 = 9, etc. Aces are the only cards whose value changes based on the other cards in the hand. Aces can either be valued at 11 or 1 depending on which gives the hand a better NON-BUSTING score.
PROPERTIES
NAME | TYPE | COMMENTS |
Value | int | The Blackjack value of the card instance |
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
BlackjackCard | face, suit | A parameterized constructor for the BlackjackCard class. Call the base constructor and calculate the Value based on the Face. |
Part B-2: BlackjackHand class
Create a BlackjackHand class that derives from the Hand class from Part A. A Blackjack Hand has a score property as it pertains to the Blackjack game. You will need to override the AddCard method to update the score of the hand after calling the base AddCard method. You will need to override the Draw method: draw the score and if it's a dealer hand, hide the first card.
The Score is the sum of the values of all the cards in the Hand. The Score should be the best score possible that is closest to 21. Aces make scoring tricky because the Aces value could change based on the other cards in the Hand. For instance, if the player has these cards in the Hand (Ace, 8), the score should be 19 (11 + 8). If a 6 card is added to the Hand, the Score would then become 15 (1 + 8 + 6), not 25 (11 + 8 + 6).
PROPERTIES
NAME | TYPE | COMMENTS |
Score | int | The blackjack score of the hand. Make the setter private. |
IsDealer | Bool | True if the hand is the dealer's hand. Default the value to false. |
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
BlackjackHand | (none) | isDealer | Make the isDealer parameter an optional parameter with the default value being false. Use isDealer to set the IsDealer property. |
AddCard | void | ICard | Override the AddCard method to update the score of the hand after calling the base AddCard method |
Draw | void | x, y | Override the draw method of the Hand class. In addition to drawing the cards, draw the score and if it's a dealer hand, hide the first card. |
NOTE: to update the score, you'll have to cast the ICard card to a BlackjackCard that has a Value property.
Part B-3: Update the Factory
Add a new method to the Card Factory that will create an instance of the BlackjackCard. Update the Deck class to call CreateBlackjackCard when creating cards.
METHODS
NAME | RETURNS | PARAMETERS | COMMENTS |
CreateBlackjackCard | ICard | face, suit | A static method that creates a BlackjackCard instance using the parameters and returns it. |
USAGE
ICard card = Factory.CreateBlackjackCard(CardFace.Ace, CardSuit.Hearts);
Part B-4: Unit Test
The scoring of your Blackjack hand is critical to your game working correctly.
To add a Unit Test project easily, right-click the BlackjackHand class and select "Create Unit Test"