SHOW:
|
|
- or go back to the newest paste.
1 | #include <vector> | |
2 | #include <iostream> | |
3 | #include <ctime> | |
4 | #include <string> | |
5 | ||
6 | using namespace std; | |
7 | ||
8 | class Card | |
9 | { | |
10 | private: | |
11 | string rank; | |
12 | string suit; | |
13 | int value; | |
14 | ||
15 | public: | |
16 | string getRank() | |
17 | {return rank;} | |
18 | ||
19 | string getSuit() | |
20 | {return suit;} | |
21 | ||
22 | int getValue() | |
23 | {return value;} | |
24 | ||
25 | Card() {} | |
26 | ||
27 | Card (string rk, string st, int val) | |
28 | - | {rank=rk; suit=st, value=val;} |
28 | + | {rank = rk; suit = st, value = val;} |
29 | ||
30 | void print() {cout << rank << "of" << suit << endl;} | |
31 | }; | |
32 | ||
33 | class Deck | |
34 | { | |
35 | private: | |
36 | Card deck[52]; | |
37 | int top; | |
38 | ||
39 | public: | |
40 | ||
41 | Card dealcard() | |
42 | {return deck[top++];} | |
43 | ||
44 | void shuffle(){} | |
45 | Deck() | |
46 | { | |
47 | - | top=0; |
47 | + | top = 0; |
48 | string ranks[13] = {"Ace", "King", "Queen", "Jack", "Ten", "Nine", "Eight", | |
49 | "Seven", "Six", "Five", "Four", "Three", "Two"}; | |
50 | ||
51 | string suits[4] = {"Hearts", "Spades", "Diamonds", "Clubs"}; | |
52 | int values[13] = {11, 10, 10, 10, 10, 9, 8, 7, 6, 5, 4, 3, 2}; | |
53 | for(int i = 0; i < 52; i++) | |
54 | deck[i] = Card( Rank[i % 13], [i % 4], [i % 13]); | |
55 | } | |
56 | }; | |
57 | ||
58 | class Player | |
59 | { | |
60 | private: | |
61 | vector<Card>hand; | |
62 | double cash; | |
63 | double bet; | |
64 | ||
65 | public: | |
66 | Player (double csh) | |
67 | { | |
68 | - | cash=csh; |
68 | + | cash = csh; |
69 | - | bet=0; |
69 | + | bet = 0; |
70 | } | |
71 | ||
72 | void hit(Card c) | |
73 | {hand.push_back(c);} | |
74 | ||
75 | int totalhand() | |
76 | { | |
77 | - | int count=0; |
77 | + | int count = 0; |
78 | ||
79 | - | for(int i=0; i<(int)hand.size();i++) |
79 | + | for(int i = 0; i < (int)hand.size(); i++) |
80 | { | |
81 | - | Card c=hand[i]; |
81 | + | Card c = hand[i]; |
82 | - | count=count + c.getValue(); |
82 | + | count = count + c.getValue(); |
83 | } | |
84 | ||
85 | - | return count;} |
85 | + | return count; |
86 | } | |
87 | ||
88 | // You need to create a new method here | |
89 | void betMoney(int amount) | |
90 | { | |
91 | if ( cash - amount < 0) | |
92 | cout << "Not enough money to bet." | |
93 | else | |
94 | { | |
95 | // Put some code here | |
96 | } | |
97 | } | |
98 | ||
99 | double getAmount() | |
100 | { return cash} | |
101 | }; | |
102 | ||
103 | int main() | |
104 | { | |
105 | bet = 0 | |
106 | // Create the instances of the objects | |
107 | Deck myDeck; | |
108 | Player me(1000), dealer(0); | |
109 | ||
110 | // Place a bet - I think you place a bet before you get your hand, though I'm not totally sure. | |
111 | cout << "You have " << me.getAmount() << " of cash. Place amount to bet" << endl | |
112 | cin >> bet | |
113 | me.betMoney(bet) // This is where you call the betting method | |
114 | ||
115 | Card c = myDeck.dealcard(); | |
116 | cout<<"Your first card is"; | |
117 | c.print(); | |
118 | me.hit(c); | |
119 | c = myDeck.dealcard(); | |
120 | cout << "Dealer showing"; | |
121 | c.print(); | |
122 | dealer.hit(c); | |
123 | ||
124 | c = myDeck.dealcard(); | |
125 | cout<<"Your second card is"; | |
126 | c.print(); | |
127 | me.hit(c); | |
128 | c = myDeck.dealcard(); | |
129 | dealer.hit(c); | |
130 | Card dealerHoldCard = c; | |
131 | ||
132 | string answer; | |
133 | cout << "More cards?"; | |
134 | cin >> answer; | |
135 | ||
136 | while(answer=="yes") | |
137 | { | |
138 | c = myDeck.dealcard(); | |
139 | cout << "Your Card is"; | |
140 | c.print(); | |
141 | me.hit(c); | |
142 | ||
143 | cout << "more?"; | |
144 | cin >> answer; | |
145 | } | |
146 | ||
147 | while(dealer.totalhand()<13) | |
148 | { | |
149 | //morecards | |
150 | } | |
151 | ||
152 | if(me.totalhand() > dealer.totalhand()) | |
153 | cout << "You win!" << endl; | |
154 | ||
155 | else | |
156 | cout << "The House Wins!" << endl; | |
157 | ||
158 | //} /* You have an extra bracket here */ | |
159 | ||
160 | return 0; | |
161 | } |