-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain-Deck.cpp
315 lines (283 loc) · 9.4 KB
/
main-Deck.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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#include <iostream>
#include <cmath>
#include "Deck2.h"
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
bool check(vector<int> card){
int temp=card[0]/4;
for(int i=0;i<card.size();i++){
if(temp==card[i]/4);
else return true;
}
return false;
}
vector<int> ChooseCard(Player P){
bool chk;
vector<int> getcard;
vector<int> cardChoose=P.GetCard();
vector<int> order;
vector<string> cFace=P.GetFace();
int choose;
char player_action ='\0';
// system("cls");
for(int i=0;i<cardChoose.size();i++){
order.push_back(i);
}
for(int i=0;i<cFace.size();i++){
if(cFace[i] == "10/5" || cFace[i] == "10/4" || cFace[i] == "10/3" || cFace[i] == "10/6"){
cout << "[" << order[i] << "] " << "|" << cFace[i] << "|" << endl;
}else{
cout << " [" << order[i] << "] " << "|" << cFace[i] << " |" << endl;
}
//Change UI
}
cout << "\n";
// for(int i=0;i<cFace.size();i++){
// cout << endl << "|" << cFace[i] << "|" << " ";
// }
// cout << "\n";
step1 :
cout << "[1] One card, [2] Pair, [3] Three of kind, [4] Four of kind \n\n"; //Add
cout << "Choose amount card = " ; //Add
cin>>player_action;
if(player_action=='1'|| player_action=='2'|| player_action=='3'|| player_action=='4'){
goto step2;
}else goto step1;
step2 :
switch(player_action){
case '1':
cout << "Choose your card :";
cin>>choose;//
getcard.push_back(cardChoose[choose]);//
break;
case '2':
for(int i=0;i<2;i++){
cout << "Choose your card :";
cin>>choose;//
getcard.push_back(cardChoose[choose]);//
}
break;
case '3':
for(int i=0;i<3;i++){
cout << "Choose your card :";
cin>>choose;//
getcard.push_back(cardChoose[choose]);//
}
break;
case '4':
for(int i=0;i<4;i++){
cout << "Choose your card :";
cin>>choose;//
getcard.push_back(cardChoose[choose]);//
}
break;
}
chk=check(getcard);
if(chk){
getcard.clear();
cout << "\n-------- Your card is not match, Please choose again--------\n";
goto step2;
}else return getcard;
}
int main(){
srand(unsigned(time(NULL)));
int num;
int maxCard;
int maxTable;
vector<int> hand;
start :
cout << "**** PLEASE PLAY ON FULL-SCREEN or HALF ****\n";
cout << "[1] Play with BOT(NOT AVALIABLE!!),[2] 2 Players,[3] 3 Players,[4] 4 Players\n"; //Add
cout << "PLAY SELECT : "; //Add
cin >> num;
if(num > 4 || num < 0) {
cout << "Please select again\n";
goto start;
}
string name[num];
cin.ignore();
for(int i=0;i<num;i++){
cout << "Please input Player "<< i+1 << " name: ";
getline(cin,name[i]);
}
Deck c1;
c1.ShuffleCard();
c1.ShuffleFace();
if(num==2){
vector<string> tmpface=c1.cardFace;
vector<string> Table;
int state=0;
int turnc=1;
vector<int> gettmp;
Player p1(name[0],c1.cardFace,c1.cards,c1.faceShuff,0,26); // get cards from deck
Player p2(name[1],c1.cardFace,c1.cards,c1.faceShuff,26,52);
p1.sortcard(); p1.sortface(); p2.sortcard(); p2.sortface(); // sorting card that get from deck
while(true){
if(turnc==1){
gettmp=p1.GetCard();
if(find(gettmp.begin(),gettmp.end(),0) != gettmp.end()){ // Check if who play first
state=1;
cout << "\n----------------Player[1] Play FIRST----------------\n\n";
}else{
state=2;
cout << "\n----------------Player[2] Play FIRST----------------\n\n";
}
if(state==1){
player1: //Player 1 first play
hand.clear();
hand=ChooseCard(p1); // function choose card
maxCard=*max_element(hand.begin(),hand.end()); // find maximun value of cards on hand to compare with value of cards on table
if(maxCard<maxTable){ // if cards on hand are less value than cards on the table -> choose cards again!
cout << "\n--------Choose your card again--------\n";
goto player1;
}else{
for(int i=0;i<hand.size();i++){
Table.push_back(tmpface[hand[i]]);
p1.eraseCard(hand[i]); // Erase cards that already used
p1.decCardCount();
}
maxTable=maxCard; // if value of cards on hand > value of cards on table you can use that cards -> put card on table
}
state=2;
}else if(state==2){
player2: //Player 2 first play
hand.clear();
hand=ChooseCard(p2); // function choose card
maxCard=*max_element(hand.begin(),hand.end()); // find maximun value of cards on hand to compare with value of cards on table
if(maxCard<maxTable){ // if cards on hand are less value than cards on the table -> choose cards again!
cout << "\n--------Choose your card again--------\n";
goto player2;
}else{
for(int i=0;i<hand.size();i++){
Table.push_back(tmpface[hand[i]]);
p2.eraseCard(hand[i]); // Erase cards that already used
p2.decCardCount();
}
maxTable=maxCard; // if value of cards on hand > value of cards on table you can use that cards -> put card on table
}
state=1;
}
turnc++;
}else{
if(state==1){
getAg1:
cout << "\n\n------------------------------- Card Table -------------------------------\n\n\n\n\n\n\n\n\n\n\n";
for(int i=0;i<Table.size();i++){
cout << " |" << Table[i] << "| ";
}
cout << "\n\n\n\n\n\n\n\n\n\n\n--------------------------------------------------------------------------\n";
cout << "\n\n---------------------------- Player[1] turn ----------------------------\n\n";
hand.clear();
hand=ChooseCard(p1); // function choose card
maxCard=*max_element(hand.begin(),hand.end()); // find maximun value of cards on hand to compare with value of cards on table
if(maxCard<maxTable){ // if cards on hand are less value than cards on the table -> choose cards again!
cout << "\n--------Choose your card again--------\n";
goto getAg1;
}else{
Table.clear();
for(int i=0;i<hand.size();i++){
Table.push_back(tmpface[hand[i]]);
p1.eraseCard(hand[i]); // Erase cards that already used
p1.decCardCount();
}
maxTable=maxCard; // if value of cards on hand > value of cards on table you can use that cards -> put card on table
}
p1.isWin();
state=2;
}else if(state==2){
getAg2:
cout << "\n\n------------------------------- Card Table -------------------------------\n\n\n\n\n\n\n\n\n\n\n";
for(int i=0;i<Table.size();i++){
cout << " |" << Table[i] << "| ";
}
cout <<"\n\n\n\n\n\n\n\n\n\n\n--------------------------------------------------------------------------\n";
cout << "\n\n---------------------------- Player[2] turn ----------------------------\n\n";
hand.clear();
hand=ChooseCard(p2); // function choose card
maxCard=*max_element(hand.begin(),hand.end()); // find maximun value of cards on hand to compare with value of cards on table
if(maxCard<maxTable){ // if cards on hand are less value than cards on the table -> choose cards again!
cout << "\n--------Choose your card again--------\n";
goto getAg2;
}else{
Table.clear();
for(int i=0;i<hand.size();i++){
Table.push_back(tmpface[hand[i]]);
p2.eraseCard(hand[i]); // Erase cards that already used
p2.decCardCount();
}
maxTable=maxCard; // if value of cards on hand > value of cards on table you can use that cards -> put card on table
}
p2.isWin();
state=1;
}
}
}
}else if(num==3){
Player p1(name[0],c1.cardFace,c1.cards,c1.faceShuff,0,17);
Player p2(name[1],c1.cardFace,c1.cards,c1.faceShuff,17,34);
Player p3(name[2],c1.cardFace,c1.cards,c1.faceShuff,34,52); // 1 more card than other
p1.sortcard();
p1.sortface();
p2.sortcard();
p2.sortface();
p3.sortcard();
p3.sortface();
}else if(num==4){
Player p1(name[0],c1.cardFace,c1.cards,c1.faceShuff,0,13);
Player p2(name[1],c1.cardFace,c1.cards,c1.faceShuff,13,26);
Player p3(name[2],c1.cardFace,c1.cards,c1.faceShuff,26,39);
Player p4(name[3],c1.cardFace,c1.cards,c1.faceShuff,39,52);
p1.sortcard();
p1.sortface();
p2.sortcard();
p2.sortface();
p3.sortcard();
p3.sortface();
p4.sortcard();
p4.sortface();
}else if(num == 1){
}
// print shuffle cards
// vector<int> caxx=p1.GetCardd();
// for(int i=0;i<26;i++){
// cout << caxx[i] << " ";
// }
// cout << endl;
// vector<string> caff=p1.GetFaced();
// for(int i=0;i<26;i++){
// cout << caff[i] << " ";
// }
// cout << endl;
// print sort cards
// vector<int> cax=p1.GetCard();
// for(int i=0;i<17;i++){
// cout << cax[i] << " ";
// }
// cout << endl;
// vector<string> caf=p1.GetFace();
// for(int i=0;i<17;i++){
// cout << caf[i] << " ";
// }
// cout << endl;
// vector<int> caxx=p2.GetCard();
// for(int i=0;i<17;i++){
// cout << caxx[i] << " ";
// }
// cout << endl;
// vector<string> caff=p2.GetFace();
// for(int i=0;i<17;i++){
// cout << caff[i] << " ";
// }
// cout << endl;
// vector<int> caxxx=p3.GetCard();
// for(int i=0;i<18;i++){
// cout << caxxx[i] << " ";
// }
// cout << endl;
// vector<string> cafff=p3.GetFace();
// for(int i=0;i<18;i++){
// cout << cafff[i] << " ";
// }
// cout << endl;
return 0;
}