Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Using C++ Create a Blackjack program with the following features: Single player game against the dealer. Numbered cards count as the number they represent (example:
Using C++
Create a Blackjack program with the following features:
- Single player game against the dealer.
- Numbered cards count as the number they represent (example: 2 of any suit counts as 2) except the Aces which can count as either 1 or 11, at the discretion of the player holding the card.
- Face cards count as 10.
- Player starts with $500.
- Player places bet before being dealt a card in a new game.
- New game: Deal 2 cards to each player with one up and one down each.
- If both the dealer and the player have 21, the result is a "Push" (meaning a tie). The game ends and the player's bet is returned to them.
- If the player or the dealer has 21, the game ends. The bet is added to their pot if they win and deducted from them if they lose.
- If neither has 21, it is the player's turn. They will continue to be offerred cards (to "Hit") to add to their total until they either exceed 21 or they choose to not take any more cards (to "Stand"). If they exceeded 21, the game ends, the player loses and their bet is deducted from their pot.
- If the player did not exceed 21, it is the dealer's turn. The dealer must continue to take cards until their sum is 17 or greater. At that point, they must "Stand" (not take any more cards).
- Whoever is closer to 21 wins and the bet is either added to or deducted from the player's pot as appropriate.
- After a game ends and money is distributed, the player is offerred another game - as long as they still have money in their pot.
- The game should have a nice, easy to understand interface.
- The code should be well documented and indented according to the specification discussed in class.
- Your program should be divided up into the following functions (which should be completely commented):
- playGame - plays a complete game of Blackjack
- getBet - prompts for and returns a valid bet by the player
- initialDeal - deals the first 2 cards to the players and determines if there was a winner - returns 0=dealer, 1=player, 2=push, 3=no winner yet.
- playerTurn - handles the player's turn - returns true if the player is still in the game or false if they busted.
- dealerTurn - handles the dealer's turn - returns true if the dealer is still in the game or false if they busted.
- deal - deals a single card into a given hand
- showHand - displays the names of the cards in the given hand - handles hidden cards
- totalHand - returns the (best) total for the cards in the given hand - handle aces here
- getCardName - given a card number, it returns the associated card name
- getCardSuit - given a card number, returns the associated card suit
- getCardValue - given a card number, returns the value of the card (1 for aces)
- checkHands - called with both hands, determines if the winner (0=dealer, 1=player, 2=push)
- initializeDeck - initialize the deck of cards
- shuffleDeck - shuffle the deck of cards
What to do:
- Completely describe the user interface that you plan to implement.
- Examine the functions above and start creating prototypes for each. Think about what data needs to be passed in and what the function will return.
- Start designing each function. Pay attention to where data is defined in each function. Make sure the data is defined at the level where it needs to be maintained.
- Add any other functions you need, but defines those outlined above.
- Complete your design by confirming to yourself that your design is solid by "running" it as we have on the board in class.
- Create a skeleton of your program using the prototypes to create function stubs.
- Write code for a function and test it thoroughly before moving on to another function.
- Repeat until the program is complete.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started