Skip to content

Instantly share code, notes, and snippets.

Created December 13, 2012 04:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4274058 to your computer and use it in GitHub Desktop.
Save anonymous/4274058 to your computer and use it in GitHub Desktop.
Blackjack Game
#include <vector>
#include <iostream>
#include <ctime>
#include <string>
using namespace std;
class Card
{
string rank;
string suit;
int value;
public:
string getRank()
{return rank;}
string getSuit()
{return suit;}
int getValue()
{return value;}
Card() {}
Card (string rk, string st, int val)
{rank=rk; suit=st, value=val;}
void print() {cout<<rank<<"of"<<suit<<endl;}
};
class Deck
{Card deck[52];
int top;
public:
Card dealcard()
{return deck[top++];}
void shuffle(){}
Deck()
{
top=0;
string ranks[13]
={"Ace","King","Queen","Jack","Ten","Nine","Eight","Seven","Six","Five","Four","Three","Two"};
string suits[4]={"Hearts","Spades","Diamonds","Clubs"};
int values[13]={11,10,10,10,10,9,8,7,6,5,4,3,2};
for(int i=0; i<52;i++)
deck[i]=Card(ranks[i % 13], suits[i % 4], values[i % 13]);
}
};
class Player
{vector<Card>hand;
double cash;
double bet;
public:
Player (double csh)
{ cash=csh;
bet=0;
}
void hit(Card c)
{hand.push_back(c);}
int totalhand()
{int count=0;
for(int i=0; i<(int)hand.size();i++)
{Card c=hand[i];
count=count + c.getValue();
}
return count;}
};
int main()
{Deck myDeck;
Player me(1000), dealer(0);
Card c = myDeck.dealcard();
cout<<"Your first card is";
c.print();
me.hit(c);
c=myDeck.dealcard();
cout<<"Dealer showing";
c.print();
dealer.hit(c);
c=myDeck.dealcard();
cout<<"Your second card is";
c.print();
me.hit(c);
c=myDeck.dealcard();
dealer.hit(c);
Card dealerHoldCard=c;
string answer;
cout<<"More cards?";
cin>>answer;
while(answer=="yes")
{c=myDeck.dealcard();
cout<<"Your Card is";
c.print();
me.hit(c);
cout<<"more?";
cin>>answer;
}
while(dealer.totalhand()<13)
{//morecards}
if(me.totalhand()>dealer.totalhand())
cout<<"You win!"<<endl;
else
cout<<"The House Wins!"<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment