-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKalashnikov Card Game.cpp
213 lines (176 loc) · 3.25 KB
/
Kalashnikov Card Game.cpp
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#include <iostream>
#include <fstream>
#include <conio.h>
#include "GameData.h"
using namespace std;
card_deck deck;
player p1, comp;
char menu();
void game();
void instructions();
void player_turn();
void comp_turn();
int main() {
char e;
do {
e = menu();
} while(e != 'e');
}
char menu() {
system("cls");
char ch, e;
cout << "Kalashnikov - The Card Game";
cout << "Main Menu";
cout << "\nP -> Play Game";
cout << "\nI -> Instructions";
cout << "\nE -> Exit Game";
ch = _getch();
switch(ch){
case 'p':
game();
break;
case 'i':
instructions();
break;
case 'e':
cout << "\n\nAre you sure? (Y / N)";
sure_exit:
e = _getch();
switch(e) {
case 'y':
break;
case 'n':
ch = e;
break;
default:
goto sure_exit;
}
}
return ch;
}
void game() {
int p1_score, ai_score;
bool over;
do {
p1_score = p1.ret_score();
ai_score = comp.ret_score();
over = false;
deck.new_game();
p1.start();
comp.start();
} while(p1.ret_score() < 20 && comp.ret_score() < 20);
system("cls");
cout << "Game Over";
if(p1_score > ai_score) {
cout << "\n\nYou Win";
}
else {
cout << "\n\nYou Lose";
}
cout << "\n\nPress any key to return to menu";
_getch();
}
void instructions() {
system("cls");
fstream file;
char ch;
file.open("Instructions_screen.dat", ios::in);
while(!file.eof()) {
ch = file.get();
cout << ch;
}
_getch();
}
void player_turn() {
char ch;
system("cls");
cout << "\nYour hand:\n";
p1.view_hand();
cout << "\n" << 52 - deck.position << " cards in deck";
cout << "\n\nYour choices:";
if(p1.kalashnikov())
cout << "\nK -> KALASHNIKOV CYKA!";
if(52 - deck.position > 0)
cout << "\nD -> Pick card from deck";
//if(deck.shelf_cards)
}
void comp_turn() {
}
void card_deck::view_shelf() {
}
void card_deck::debug_view() {
for(int i = 0; i < 52; i++) {
cards[i].disp();
}
}
void player::start() {
for(int i = 0; i < 4; i++) {
pick_card(-1);
hand[i] = picked;
}
}
void player::pick_card(int c) {
if(c == -1)
equate(deck.pick_from_deck());
else
equate(deck.pick_from_shelf(c));
}
void player::discard_card(int pos) {
switch(pos) {
case 4:
deck.put_to_garbage(picked);
break;
default:
deck.put_to_garbage(hand[pos]);
hand[pos] = picked;
}
}
void player::put_card_shelf(int pos) {
switch(pos) {
case 4:
deck.put_to_shelf(picked);
break;
default:
deck.put_to_shelf(hand[pos]);
hand[pos] = picked;
}
}
void player::view_hand() {
for(int i = 0; i < 4; i++) {
hand[i].disp();
}
}
void player::view_picked() {
picked.disp();
}
void card::disp() {
switch(value) {
case 1:
cout << "A" << '\t';
break;
case 13:
cout << "K" << '\t';
break;
case 12:
cout << "Q" << '\t';
break;
case 11:
cout << "J" << '\t';
break;
default:
cout << value << '\t';
}
switch(suit) {
case SPADE:
cout << "Spade" << "\t\n";
break;
case HEART:
cout << "Heart" << "\t\n";
break;
case CLUB:
cout << "Club" << "\t\n";
break;
case DIAMOND:
cout << "Diamond" << "\t\n";
}
}