Question

Need a blackjack code for my assignment its due in 3 hours: it has to include...

Need a blackjack code for my assignment its due in 3 hours: it has to include classes and object C++.

Create a fully functioning Blackjack game in three separate phases. A text based version with no graphics, a text based object oriented version and lastly an object oriented 2D graphical version. Credits (money) is kept track of throughout the game by placing a number next to the player name. Everything shown to the user will be in plain text. No graphics are needed in this submission. The player will be given options for what can be done during their turn. I.e., Hit ‘h’, Stand ‘s’, Split(p), DoubleDown (d), etc…  Game Mechanics  Shuffle Deck  Deal Cards  Request a Card (Hit)  Stay on Current Cards (Stand)  Splitting Pairs  Double Down  Surrender Hand  Betting System Game must have the following Blackjack rules implemented:  Purpose of the game is to get as close to 21 points without going over  Player starts with two cards both facing up  Player places bets before cards a dealt  Player can request a card or stand based on the card values  If hand is a pair, it can be split into two hands and another card is dealt for each hand (Can only be done once in this version)  Split gives player two hands to play  Split doubles bet for the current round  Player can double down on current hand  Double down is a request for a single card added to the current hand after the cards are first dealt  Double down can only be used once per hand  Double down can be used on a split  Player can surrender if dealer is showing an ace as their face card  Surrender is only available as first decision of a hand and is the option to "surrender" directly after the dealer has checked for blackjack  House takes half the bet and returns the other half to the player; this terminates the player's interest in hand Dealer gets two cards, one card face up and the other face down  Dealer can shuffle deck  Deal (Two cards face up to player, one card face up to dealer and one card face down)  Dealer can Hit or Stand based on dealer rules  Dealer must stand on 17  Dealer must hit until 17 or more  Scoring  Face cards are worth 10 points each (J, Q, K)  Other cards are worth the number on the Card (2,3,4,5,6,7,8,9,10)  Ace is either a 1 or 11 depending on hand total.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Blackjack.cpp

#include "stdafx.h"
#include "Blackjack.h"


Blackjack::Blackjack()
{
    srand(time(0));
    dhandSize = 0;
    phandSize = 0;
    dhandSum = 0;
    phandSum = 0;
    playerDone = false;
    dealerDone = false;
}

void Blackjack::playGame()
{
    cout << "Welcome to Blackjack!\n";

    // Start the player and dealer with two cards
    addPlayerCard();
    addPlayerCard();
    addDealerCard();
    addDealerCard();
    sumHands();
    printHand();

    if (dhandSum == 21)
    {
        cout << "Dealer has blackjack. Dealer wins.\n";
        return;
    }
    else if (phandSum == 21)
    {
        cout << "Player has blackjack. Player wins.\n";
        return;
    }

    while (dealerDone == false || playerDone == false)
    {
        if (playerDone == false)
        {
            cout << "Would you like to hit? (1 - Yes, 2 - No)\n";
            cin >> phit;

            if (phit == 1)
            {
                addPlayerCard();
                printHand();
                sumHands();

                if (phandSum > 21)
                {
                    cout << "Player's hand exceeded 21. Player loses.\n";
                    return;
                }
            }
        }

        if (playerDone == false)
        {
            cout << "Would you like to stand? (1 - Yes, 2 - No)\n";
            cin >> pstand;
        }

        if (pstand == 1)
        {
            playerDone = true;
        }

        if (dhandSum < 17 && dealerDone != true)
        {
            addDealerCard();
            printHand();
            sumHands();

            if (dhandSum > 21)
            {
                cout << "Dealer hand exceeded 21. Dealer loses.\n";
                return;
            }
        }
        else if (dhandSum >= 17)
        {
            dealerDone = true;
        }

        if (phandSum == 21 && dhandSum == 21)
        {
            cout << "Push, player and dealer reached 21.\n";
            return;
        }
        else if (phandSum == 21)
        {
            cout << "Player reached 21. Player wins.\n";
            return;
        }
        else if (dhandSum == 21)
        {
            cout << "Dealer reached 21. Dealer wins.\n";
            return;
        }

        if ((playerDone == true && dealerDone == true) || (phandSize == 5 && phandSize == 5))
        {
            if (dhandSum < phandSum)
            {
                cout << "Sum of your hand exceeds the dealer's sum of " << dhandSum << "! You win!";
                return;
            }
            else if (phandSum == dhandSum)
            {
                cout << "Dealer sum of " << dhandSum << " is equal to the sum of your hand. Tie game.";
                return;
            }
            else if (dhandSum > phandSum)
            {
                cout << "Sum of your hand is lower than the dealer's sum of " << dhandSum << ". You lose!";
                return;
            }
        }
    }
}

int dhand[5];
int phand[5];
int dhandSize;
int phandSize;
int dhandSum;
int phandSum;
int phit;
int pstand;
bool playerDone;
bool dealerDone;

void Blackjack::addPlayerCard()
{
    if (phandSize <= 5)
    {
        phand[phandSize] = 1 + (rand() % 11);
        phandSize++;
    }
    else
    {
        cout << "Sorry. You have reached the maximum number of cards (5)." << endl;
        playerDone = true;
    }
}

void Blackjack::addDealerCard()
{
    if (dhandSize <= 5)
    {
        dhand[dhandSize] = 1 + (rand() % 11);
        dhandSize++;
    }
    else
    {
        dealerDone = true;
    }
}

void Blackjack::printHand()
{
    cout << "Your current hand is...\n";

    for (int i = 0; i < phandSize; i++)
    {
        cout << "    -" << phand[i] << "-    \n\n";
    }

    cout << "Dealer's current hand is...\n";

    for (int j = 0; j < dhandSize; j++)
    {
        cout << "    -" << dhand[j] << "-    \n\n";
    }
}

void Blackjack::sumHands()
{
    dhandSum = 0;
    phandSum = 0;
    for (int i = 0; i < dhandSize; i++)
    {
        dhandSum += dhand[i];
    }

    for (int j = 0; j < phandSize; j++)
    {
        phandSum += phand[j];
    }

    cout << "Current player hand sum is: " << phandSum << endl;
}

main.cpp

#include "stdafx.h"
#include "Blackjack.h"


int main()
{

    int exitGame = 1;

    do
    {
        Blackjack casino_royale;
        casino_royale.playGame();
        cout << "\nWould you like to play again? (1 - Yes, 2 - No)\n";
        cin >> exitGame;
    }while (exitGame == 1);


    cout << "\nThanks for playing!\n";
    system("pause");
    return 0;
}

Blackjack.h

#pragma once
#include "stdafx.h"


class Blackjack
{
public:
    Blackjack();
    void playGame();

private:
    int dhand[5];
    int phand[5];
    int dhandSize;
    int phandSize;
    int dhandSum;
    int phandSum;
    int phit;
    int pstand;
    bool playerDone;
    bool dealerDone;
    void addPlayerCard();
    void addDealerCard();
    void printHand();
    void sumHands();
};
Add a comment
Know the answer?
Add Answer to:
Need a blackjack code for my assignment its due in 3 hours: it has to include...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a simplified Blackjack game using the Deck and Card classes (download the attached files to...

    Create a simplified Blackjack game using the Deck and Card classes (download the attached files to start).  There is also a "TestCard" class that creates a Deck and runs some simple code. You may choose to use this file to help you get started with your game program. 1) Deal 2 cards to the "player" and 2 cards to the "dealer".  Print both the player's cards, print one of the dealer's cards. Print the total value of the player's hand. 2) Ask...

  • Using C++ Create a Blackjack program with the following features: Single player game against the dealer....

    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...

  • 4. In one version of the game played by a dealer and a player, 2 cards...

    4. In one version of the game played by a dealer and a player, 2 cards of a standard 52-card bridge deck are dealt to the player and 2 cards to the dealer. For this exercise, assume that drawing an ace and a face card (Jack, Queen and King for each shape) is called blackjack. If the dealer does not draw a blackjack and the player does, the player wins. If both the dealer and player draw blackjack, a tie...

  • This is a question for a stats course for science students... In one version of the...

    This is a question for a stats course for science students... In one version of the game played by a dealer and a player, 2 cards of a standard 52-card bridge deck are dealt to the player and 2 cards to the dealer. For this exercise, assume that drawing an ace and a face card (Jack, Queen and King for each shape) is called blackjack. If the dealer does not draw a blackjack and the player does, the player wins....

  • In the game of blackjack, the player is initially dealt two cards from a deck of...

    In the game of blackjack, the player is initially dealt two cards from a deck of ordinary playing cards. Without going into all the details of the game, it will suffice to say here that the best possible hand one could receive on the initial dear is a combination of an ace of any suit and any face card or 10. What is the probability that the player will be dealt this combination?

  • NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET...

    NEED HELP TO CREATE A BLACKJACK GAME WITH THE UML DIAGRAM AND PROBLEM SOLVING TO GET CODE TO RUN!! THANKS Extend the DeckofCards and the Card class in the book to implement a card game application such as BlackJack, Texas poker or others. Your game should support multiple players (up to 5 for BlackJack). You must build your game based on the Cards and DeckofCards class from the book. You need to implement the logic of the game. You can...

  • How do I start this c++ code homework? Write a code in C++ for a BlackJack...

    How do I start this c++ code homework? Write a code in C++ for a BlackJack card game using the following simplified rules: Each card has a numerical value. Numbered cards are counted at their face value (two counts as 2 points, three, 3 points, and so on) An Ace count as either 1 point or 11 points (whichever suits the player best) Jack, queen and king count 10 points each The player will compete against the computer which represents...

  • the card game Acey Deucey, which is also known by several other names. In general, the...

    the card game Acey Deucey, which is also known by several other names. In general, the game is played with three or more people that continue to gamble for a pot of money. The pot grows and shrinks depending on how much General description of the game ● Two cards are dealt face up to a player from a shuffled deck of cards. ○ If the face of each card is the same then the player adds $1 into the...

  • Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores...

    Player Class Represents a participant in the game of blackjack. Must meet the following requirements: Stores the individual cards that are dealt (i.e. cannot just store the sum of the cards, you need to track which specific cards you receive) Provided methods: decide_hit(self): decides whether hit or stand by randomly selecting one of the two options. Parameters: None Returns: True to indicate a hit, False to indicate a stand Must implement the following methods: Hi!! i just need help with...

  • Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June...

    Please to indent and follow structure!!!!! Assignment 3 - The card game: War Due Date: June 9th, 2018 @ 23:55 Percentage overall grade: 5% Penalties: No late assignments allowed Maximum Marks: 10 Pedagogical Goal: Refresher of Python and hands-on experience with algorithm coding, input validation, exceptions, file reading, Queues, and data structures with encapsulation. The card game War is a card game that is played with a deck of 52 cards. The goal is to be the first player to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT