This repository has been archived by the owner on May 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMain.cpp
109 lines (92 loc) · 2.81 KB
/
Main.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
#include <iostream>
#include <fstream>
#include <string>
#include "Card.h"
#include "Table.h"
using namespace std;
int main() {
cout << "Would you like to type the file name to load the game? Or, type 'new' to start a new game." << endl;
string filename;
cin >> filename;
cout << "--------------------------------------" << endl;
ifstream file(filename);
ifstream iF;
if (filename != "new") {
iF.open(filename);
}
else {
ofstream in("GameData.txt", fstream::out);
iF.open("GameData.txt");
}
string n1;
cout << "Player 1: What is your name?" << std::endl;
cin >> n1;
cout << "--------------------------------------" << endl;
string n2;
cout << "Player 2: What is your name?" << std::endl;
cin >> n2;
cout << "--------------------------------------" << endl;
CardFactory *factory = factory->getFactory(file);
Table* table = new Table(iF, factory);
table->A = new Player(n1);
table->B = new Player(n2);
//Number of Cards in the Whole Deck
int ctr0 = 0;
for (Card* card : table->deck)
ctr0++;
cout << "Number of cards in the whole shuffled deck: " << ctr0 << endl;
cout << "--------------------------------------" << endl;
// Drawing 5 cards for Player 1.
for (int i = 0; i < 5; i++)
table->A->getPlayersHand()->operator+=(table->deck.draw());
// Drawing 5 cards for Player 2.
for (int i = 0; i < 5; i++)
table->B->getPlayersHand()->operator+=(table->deck.draw());
//Printing table
print(cout, *table);
Player* pArray[]{table->A, table->B};
while (!table->deck.empty()) {
if (false) {
break;
}
for (Player* p : pArray){
cout << "--------------------------------------" << endl;
cout << "Top card of both Players hand:" << endl;
table->printHand(false); // Top cards;
for (Chain<Card*> chain : p->getChain()) {
int num = 1;
cout << p->getName() << num << " Chain [ ";
for (int i = 0; i < int(chain.getChain().size()); ++i)
cout << chain.getChain()[i]->getName() << ' ';
cout << "]" <<endl;
num++;
}
if (!table->tArea->getTradeArea().empty()) {
cout << "From TradeArea to Chain[c]? Or, discard them[d]? The default is to discard" << endl;
string ans;
cin >> ans;
if (ans == "c") {
for (Card* card : table->tArea->getTradeArea()) {
for (Chain<Card*> chain : p->getChain()) {
if (chain.getChain()[0]->getName() == card->getName()) {
chain.getChain().push_back(card);
}
}
}
}
else {
for (Card* card : table->tArea->getTradeArea()) {
table->dPile->operator+=(table->tArea->trade(card->getName()));
}
}
}
for (Chain<Card*> chain : p->getChain()) {
if (chain.getChain()[0]->getName() == p->getPlayersHand()->top()->getName()
|| ((Card*)(chain.getChain().empty()))) {
chain.getChain().push_back((Card*)(p->getPlayersHand()->play()));
}
}
}
break;
}
}