-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cc
249 lines (236 loc) · 5.66 KB
/
main.cc
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
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <utility>
#include "player.h"
#include "textdisplay.h"
#include "board.h"
#include "card.h"
#include <memory>
using namespace std;
int main(int argc, char* argv[]) {
Player p1;
Player p2;
Board b;
string mode; //What mode?
string display; //what display?
TextDisplay t;
ifstream f;
const string helpmsg = "Commands: help -- Display this message.\n"" "
"end -- End the current player's turn.\n"" ""quit -- End the game.\n"" "
"attack minion other-minion -- Orders minion to attack other-minion.\n"" "
"attack minion -- Orders minion to attack the opponent.\n"" "
"play card [target-player target-card] -- Play card, optionally targeting target-card owned by target-player.\n"
" "
"use minion [target-player target-card] -- Use minion's special ability, optionally targeting target-card owned by target-player.\n"
" "
"inspect minion -- View a minion's card and all enchantments on that minion.\n"" "
"hand -- Describe all cards in your hand.\n"" "
"board -- Describe all cards on the board.";
bool init = false;
b.setActPlayer(&p1);
b.setInActPlayer(&p2);
Player *activePlayer = b.getActive();
Player *inactivePlayer = b.getInactive();
p1.setdeck("default.deck");
p2.setdeck("default.deck");
p1.setBoard(&b);
p2.setBoard(&b);
p2.setMaxMagic(2);
for (int i = 1; i < argc; ++i) {
string temp = argv[i];
if (temp == "-deck1") {
++i;
string temp2 = argv[i];
p1.setdeck(temp2);
}
else if (temp == "-deck2") {
++i;
string temp3 = argv[i];
p2.setdeck(temp3);
}
else if (temp == "-init") {
++i;
string temp2 = argv[i];
f.open(temp2);
//read command from file
init = true;
}
else if (temp == "-testing") {
mode = "t";
}
else if (temp == "-graphics") {
display = "g";
}
}
if (mode != "t") { //shuffle
p1.shuffleDeck();
p2.shuffleDeck();
p2.shuffleDeck();
}
for (int i = 0; i < 5; ++i) {
p1.draw();
}
for (int i = 0; i < 5; ++i) {//should be 5
p2.draw();
}
string name1;
string name2; //Player names
if (init) {
getline(f,name1);
p1.setName(name1);
getline(f,name2);
p2.setName(name2);
}
else {
cout << "Player1 please enter your name:" << endl;
getline(cin,name1);
p1.setName(name1);
cout << "Player2 please enter your name:" << endl;
getline(cin,name2);
p2.setName(name2);
}
//game loop
string cmd;
string line; //the whole line
while (true) {
if (init) {
getline(f,line);
if (!f.good()) {
init = false;
}
}
if (!init) {
getline(cin,line);
if (!cin.good()) {
break;
}
}
stringstream ss{ line };
ss >> cmd;
if (cmd == "help") {
cout << helpmsg << endl;
}
else if (cmd == "end") {
activePlayer->endTurn();
inactivePlayer->startTurn();
b.swapTurn();
swap(activePlayer,inactivePlayer);
}
else if (cmd == "draw" && mode == "t") {
activePlayer->draw();
}
else if (cmd == "discard" && mode == "t") {
int index;
ss >> index;
--index;
if (index < activePlayer->getHand().size()){
activePlayer->discard(index);
} else {
cout << "Invalid hand card index! " << endl;
}
}
else if (cmd == "attack") {
int i; //active player index
ss >> i;
--i;
int j; //inactive player index
if (!(ss >> j)) {
if (activePlayer->getMinion().size() > i){
activePlayer->getMinion()[i]->attack(inactivePlayer);}
else {
cout << "Invalid index! Please try again!" << endl;
} //Player::attack face
} else {
--j;
activePlayer->attack(i, j);
}
}
else if (cmd == "play") {
int i; //active player index
ss >> i;
int p; //which player
--i;
if (!(ss >> p)) {
activePlayer->play(i); //just play it
}
else {
int j; //inactive player index
ss >> j;
--j;
if (p==1) {
if(j < p1.getMinion().size()) {
activePlayer->play(i,p1.getMinion().at(j));
}
else {
cout << "Invalid hand card index" << endl;
}
}
else {
if (p2.getMinion().size() > j){
activePlayer->play(i,p2.getMinion().at(j));
} else {
cout << "Invalid hand card index" << endl;
}
}
}
}
else if (cmd == "use") {
int i; //active player index
ss >> i;
int p;
--i;
if (!(ss >> p)) {
activePlayer->useActive(i); //use activated ability on no target
}
else {
int j;
ss >> j;
--j;
if (p==1){
if (j<p1.getMinion().size()){
activePlayer->useActive(i,p1.getMinion().at(j));
} else {
cout << "Invalid hand card index!" << endl;
}
}
else {
if (j<p1.getMinion().size()){
activePlayer->useActive(i,p2.getMinion().at(j));}
else {
cout << "Invalid hand card index!" << endl;
}
}
}
}
else if (cmd == "inspect") {
int i;
ss >> i;
--i;
if (i<activePlayer->getMinion().size()) {
shared_ptr<Card> temp = activePlayer->getMinion().at(i);
t.inspectMinion(temp);
} else {
cout << "Invalid hand card index!" << endl;
}
}
else if (cmd == "hand") {
t.displayHand(activePlayer);
}
else if (cmd == "board") {
t.displayBoard(&b);
}
else {
cout << "invalid command" << endl;
}
if (p1.isDead()) {
cout << "Game Over! Player 2 wins!!" << endl;
break;
}
if (p2.isDead()) {
cout << "Game Over! Player 1 wins!!" << endl;
break;
}
}
}