logo

Short Explanation of Game- Blackjack

   

Added on  2019-10-16

16 Pages3992 Words288 Views
1.Name and date2.A short explanation of the game and how it worksBlackjack is also known as twenty-one. It is a game played between the computer and the player.In this game, two cards are given to each player and dealer randomly. Player's both cards have face up and computer's only one card has face up.Player can win if the sum of its cards is 21(perfect blackjack), or if the sum of his cards is less than 21 and greater than computer's, or if the sum of computer's cards is greater than 21.Player will lose if the sum of his cards is greater than 21 or if the sum is less than computer's cards' sum. Now the player has two options – hit or stand.Hit- Take another undealt card from the deck.Stand- Do not take any card and let the computer play its turn.If the sum of player's two cards is quite less than 21(usually less than 15 or 16), he can hit and get another card to make the sum greater and the player can hit as many times as he wants until the sum is greater than 21.If the sum of computer's first two cards is less than 17, computer too will getanother card until the sum exceeds 17.The value of ace depends on the player, he can take it 1 or 11 depending upon the need.3. List of all major variables used in the program and what they are used forplay_cards value– object of class play_cards to invoke the play function that controls the flow of the game.int p_total– integer representing the sum of card values of the player.int c_total – integer representing the sum of card values of the computer.deck p_cards[5] – array of structure deck to contain the card information of the cards of the player.deck c_cards[5] - array of structure deck to contain the card information of the cards of the computer.deck shuf[52] - array of structure deck to contain the card information initially loaded in order to shuffle the cards in function shuff.struct deck

{ string card_name; string card_type; int card_value; bool dealt; }; - structure containing the information of any card.deck card[52] – array of structure deck to load the card information initially.4. Source Code#include <iostream>#include <string>#include <stdio.h>#include <time.h>#include <stdlib.h>using namespace std;class play_cards{private:struct deck{string card_name;string card_type;int card_value;bool dealt;};public:void load();void printdeck();int shuff(deck cards[]);int convert_jkq(int a);void print(deck num);int play(void);deck card[52];int i;};int main(){play_cards value;value.load();value.printdeck();system("pause");char again;

do{value.play();cout<<"\nWould you like to play again? Input 'y' or 'n':\n";do{again = getchar();} while (again!='y' && again!='n');if (again == 'y'){cout<<"\nOK, let's go again!\n\n";}}while(again == 'y');return 0;}void play_cards::load(){card[0].card_name="TWO";card[0].card_type="heart";card[0].card_value=2;card[0].dealt=false;card[1].card_name="THREE";card[1].card_type="heart";card[1].card_value=3;card[1].dealt=false;card[2].card_name="FOUR";card[2].card_type="heart";card[2].card_value=4;card[2].dealt=false;card[3].card_name="FIVE";card[3].card_type="heart";card[3].card_value=5;card[3].dealt=false;card[4].card_name="SIX";card[4].card_type="heart";card[4].card_value=6;card[4].dealt=false;card[5].card_name="SEVEN";card[5].card_type="heart";card[5].card_value=7;card[5].dealt=false;card[6].card_name="EIGHT";card[6].card_type="heart";card[6].card_value=8;card[6].dealt=false;card[7].card_name="NINE";

card[7].card_type="heart";card[7].card_value=9;card[7].dealt=false;card[8].card_name="TEN";card[8].card_type="heart";card[8].card_value=10;card[8].dealt=false;card[9].card_name="ACE";card[9].card_type="heart";card[9].card_value=1;card[9].dealt=false;card[10].card_name="JACK";card[10].card_type="heart";card[10].card_value=10;card[10].dealt=false;card[11].card_name="QUEEN";card[11].card_type="heart";card[11].card_value=10;card[11].dealt=false;card[12].card_name="KING";card[12].card_type="heart";card[12].card_value=10;card[12].dealt=false;card[13].card_name="TWO";card[13].card_type="diamond";card[13].card_value=2;card[13].dealt=false;card[14].card_name="THREE";card[14].card_type="diamond";card[14].card_value=3;card[14].dealt=false;card[15].card_name="FOUR";card[15].card_type="diamond";card[15].card_value=4;card[15].dealt=false;card[16].card_name="FIVE";card[16].card_type="diamond";card[16].card_value=5;card[16].dealt=false;card[17].card_name="SIX";card[17].card_type="diamond";card[17].card_value=6;card[17].dealt=false;card[18].card_name="SEVEN";card[18].card_type="diamond";

End of preview

Want to access all the pages? Upload your documents or become a member.

Related Documents
Advanced C++ Assignment - Playing Blackjack (21)
|2
|783
|279