Question
Create a BlackJack Game: Must look as it does in example exe https://drive.google.com/file/d/0B-ZaUH1-dG1dcmxHQWRwR2FyWDA/view?usp=sharing Your assignment is to design and implement a complete C++ program that
Create a BlackJack Game:
Must look as it does in example exe
https://drive.google.com/file/d/0B-ZaUH1-dG1dcmxHQWRwR2FyWDA/view?usp=sharing
Your assignment is to design and implement a complete C++ program that plays the game interactively with 7 players. To observe how the program works, you can download and execute the file BlackJack.exe. To execute the program, copy the executable file BlackJack.
Rules for BlackJack (also called 21) 1) This game will be played with a standard straight deck of 52 cards. Each card has a suit (heart, diamond, club, or spade) and a rank (Ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, Jack, Queen, or King). The value of a card is 1 for an Ace; ranks 210 have a value equal to their rank, and the Jack, Queen, and King have a value of 10. 2) This game will be played with seven players, each against the dealer. 3) The game begins by dealing two cards to each of the players and the dealer. One of the dealer cards is not exposed. 4) Each player in turn can ask for many additional cards as s/he wishes, one at a time. If a players total exceeds 21, that player automatically loses to the dealer and is no longer in that game. 5) After each player has received all their cards, the dealer must take additional cards until the dealers total is at least 17, after which he can take no more cards. 6) If the dealer has a total > 21, all remaining players with total < 22 win. Otherwise, each player wins if has a greater total than the dealer, or the dealer wins if he has a total greater than the player. Nobody wins on a tie. 7) More about Win/Lose/Tie a. The dealer does not get a designation of W/L/T. b. Each player is playing against the dealer and NOT against other players. c. A player ties the dealer if the dealer is under 22 and both that player and the dealer have the same totals. d. A player wins the dealer if: 1) The dealer is over 21 and the player is under 22. OR 2) Both player and dealer under 22 and the player's total is higher than the dealer's total e. A player lose to the dealer if: 1) The player is over 21. OR 2) The player's total is less than the dealer's total and the dealer is under 22.
Hints for Lab 3
Think how the game is played. If you are not sure about a rule, ask me. Think of me as your customer and you are writing a program for me.
Break down the problem to sub problems. Here are some suggestion:
Shuffle the deck using rand()%52; Remember to use srand(time(Null));
Write a function to print your header.
Write a function to deal two cards to each player. Keep one of the cards dealt to the dealer covered or only deal one card to the dealer.
Write a function to update on the screen the total for a player. As you deal them another card, the total should be updated accordingly. Use row 15 for your totals.
You always give a player a choice to take a card or pass. When a player passes his turn, her/his total remains for the duration of the game.
When dealing a card, a function is called to generate the next available card.
Gotoxy(column,row) will position your cursor at that location and what you send using the cout function will print to that location on the screen. Therefore, you need to keep track for each player what is the next row to write to. The column can be calculated using 0 to start for dealer and add 7 for each player. Therefore, after dealing the first two cards, dealers third card when dealt will be placed in 0,3 using gotoxy(0,3) and the first players third card will be placed in 7,3 using gotoxy(7,3) and so on.
When printing a card value to the screen, right justify to line up your suit.
A=1, J=10, Q=10, and K=10. Hint: A % operator will work great to know what card you picked. A switch statement may come in handy to assign values for these cards. Keep in mind that A, J, Q, K must be displayed as A, J, Q, and K.
Use an array to hold your cards. There are four suits in a deck and 13 cards for a suit (A, 210, J, Q, and K). Using a / operator with a switch statement can pin point the suit of the selected card.
To print a suit after detecting it, char(3), char(4), char(5) and char(6) will print heart, diamond, club, and spade respectively.
The function Another_Card will ask if you want to receive a card for the current player. If yes, then call the appropriate function and display the selected card. Otherwise, move on to the next player.
An additional 10% will be awarded for a program that will allow a user to play another game without restarting it. Hint a call to a system function cls will clear the screen for you.
A function to finish the dealer after all players are done. This function will display the first card to the dealer and will automatically finish the dealer according to the rules.
A function to calculate users status after the dealer is done. Win Lose, or Tie.
Starter Code:
#include
#include
#include
#include
using namespace std;
//#include
// col row
void gotoxy(int h, int w)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (INVALID_HANDLE_VALUE != hConsole)
{
COORD pos = { h, w };
SetConsoleCursorPosition(hConsole, pos);
}
return;
}
char FindPicture(int);
int main()
{
int cards[52], picked[52] = { 0 }, i, j, card, suit, value, total[8] = { 0 };
char picture;
srand(time(NULL));
cout << char(3) << char(4) << char(5) << char(6) << endl;
i = 0;
while (i < 52)
{
card = rand() % 52;
//while (picked[card] == 1)
while (picked[card])
card = rand() % 52;
cards[i] = card;
picked[card] = 1;
i++;
}
i = 0;
while (i < 52)
{
suit = cards[i] / 13;
picture = FindPicture(cards[i]);
/*switch (cards[i] % 13)
{
case 0: picture = 'A';
break;
case 10: picture = 'J';
break;
case 11: picture = 'Q';
break;
case 12: picture = 'K';
break;
default: picture = ' ';
}*/
if (cards[i] % 13 < 10)
value = cards[i] % 13 + 1;
else
value = 10;
if (picture == ' ')
cout << setw(2) << cards[i] << setw(3) << value << char(suit+3) << endl;
else
cout << setw(2) << cards[i] << setw(3) << picture << char(suit+3) << endl;
i++;
}
cout << endl;
//right justify the output
cout << right;
system("cls");
gotoxy(0, 0);
cout << setw(8) << "dlr" << setw(8) << "plr1" << setw(8) << "plr2"
<< setw(8) << "plr3" << setw(8) << "plr4" << setw(8) << "plr5"
<< setw(8) << "plr6" << setw(8) << "plr7" << endl;
gotoxy(0, 1);
cout << setw(8) << "===" << setw(8) << "====" << setw(8) << "===="
<< setw(8) << "====" << setw(8) << "====" << setw(8) << "===="
<< setw(8) << "====" << setw(8) << "====" << endl;
// Follow up here from 1:20 to end of lecture
i = 0;
while (i < 8)
{
// gotoxy(column,row)
gotoxy(i * 8, 2);
suit = cards[i] / 13;
/*switch (cards[i] % 13)
{
case 0: picture = 'A';
break;
case 10: picture = 'J';
break;
case 11: picture = 'Q';
break;
case 12: picture = 'K';
break;
default: picture = ' ';
}*/
picture = FindPicture(cards[i]);
//create a function to return a value calculated in this if else statement.
if (cards[i] % 13 < 10)
value = cards[i] % 13 + 1;
else
value = 10;
if (picture == ' ')
cout << setw(7) << value << char(suit + 3) << endl;
else
cout << setw(7) << picture << char(suit + 3) << endl;
i++;
}
system("pause");
return 0;
}
char FindPicture(int card)
{
char picture = ' ';
switch (card % 13)
{
case 0: picture = 'A';
break;
case 10: picture = 'J';
break;
case 11: picture = 'Q';
break;
case 12: picture = 'K';
break;
default: picture = ' ';
}
return picture;
}
Link to .exe file
https://drive.google.com/file/d/0B-ZaUH1-dG1dcmxHQWRwR2FyWDA/view?usp=sharing
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