public
anonymous / BJC++
Created

Blackjack Game

  • Download Gist
BJC++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
 
#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(Rank[i%13],[i%4],[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;
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.