-
Notifications
You must be signed in to change notification settings - Fork 1
/
Card.cpp
243 lines (221 loc) · 4.71 KB
/
Card.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
#include "Card.h"
#include<fstream>
#include "DecWalletCard_1.h"
#include"Nextcard.h"
#include"card3.h"
#include"card4.h"
#include"card5.h"
#include"card6.h"
#include"card7.h"
#include"card8.h"
#include"card9.h"
#include"card10.h"
#include "card11.h"
#include"card12.h"
#include "card13.h"
#include "card14.h"
#include "card15.h"
Card::Card(const CellPosition & pos) : GameObject(pos) // sets the cell position of the GameObject
{
Type = 4;
}
void Card::SetCardNumber(int cnum)
{
if(cnum<1 || cnum>15)
return;
else
cardNumber = cnum; // needs validation
}
int Card::GetCardNumber()
{
return cardNumber;
}
void Card::Draw(Output* pOut) const
{
pOut->DrawCell(position,cardNumber);
///TODO: call the appropriate Ouput function that draws a cell containing the "cardNumber" in "position"
}
void Card::ReadCardParameters(Grid * pGrid)
{
// we should not make it pure virtual because some Cards doesn't have parameters
// and if we make it pure virtual, that will make those Cards abstract classes
}
void Card::Apply(Grid* pGrid, Player* pPlayer)
{
// The following line is to print the following message if a player reaches a card of any type
pGrid->PrintErrorMessage("You have reached card " + to_string(cardNumber) + ". Click to continue ...");
int x=0; int y=0;
pGrid->GetInput()->GetPointClicked(x,y);
}
void Card::settaken(int x)
{
}
int Card::gettaken()
{
return 5;
}
void Card::setmor(int x)
{
}
int Card::getmor()
{
return 5;
}
int Card::getfee()
{
return 0;
}
int Card::getprice()
{
return 0;
}
void Card::setprice(int x)
{
}
void Card::setfees(int x)
{
}
void Card::setoffer(bool x)
{
}
bool Card::getoffer()
{
return false;
}
void Card::reset()
{
}
void Card::setmade(bool x)
{
}
void Card::setload(bool x)
{
}
Card::~Card()
{
}
void Card::Save(ofstream& OutFile, Grid* pGrid, int typ)
{
if (typ != Type)
{
return;
}
if (!OutFile.is_open())
{
return;
}
else
{
OutFile << GetCardNumber() << " " << GetPosition().GetCellNum() << " ";
}
}
void Card::Load(ifstream& InFile,Grid* pGrid, int typ)
{
if (typ != Type)
{
return;
}
if (!InFile.is_open())
{
return;
}
else
{
CellPosition pos;
int CellNum;
int cardNum;
InFile >> cardNum;
InFile >> CellNum;
Card* pCard = NULL;
switch (cardNum)
{
case 1:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new DecWalletCard_1(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 2:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new Nextcard(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 3:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card3(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 4:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card4(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 5:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card5(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 6:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card6(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 7:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card7(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 8:
pos = pos.GetCellPositionFromNum(CellNum);
SetCardNumber(cardNum);
SetPosition(pos);
pCard = new card8(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 9:
pos = pos.GetCellPositionFromNum(CellNum);
SetCardNumber(cardNum);
SetPosition(pos);
pCard = new card9(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 10:
pos = pos.GetCellPositionFromNum(CellNum);
SetCardNumber(cardNum);
SetPosition(pos);
pCard = new card10(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 11:
pos = pos.GetCellPositionFromNum(CellNum);
SetCardNumber(cardNum);
SetPosition(pos);
pCard = new card11(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 12:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card12(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 13:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card13(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 14:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card14(pos);
pCard->Load(InFile, pGrid, 4);
break;
case 15:
pos = pos.GetCellPositionFromNum(CellNum);
pCard = new card15(pos);
pCard->Load(InFile, pGrid, 4);
break;
}
if (pCard)
{
pGrid->AddObjectToCell(pCard);
}
}
}