-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclasses.cpp
More file actions
237 lines (204 loc) · 5.11 KB
/
Copy pathclasses.cpp
File metadata and controls
237 lines (204 loc) · 5.11 KB
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
#include <iostream>
#include <ctime>
#include <cstdlib> //ctime and cstdlib used for the srand(time(0)) and rand())
#include "skillCompendium.cpp"
#include "stats.cpp"
using namespace std;
//--
extern skill w1, w2, w3, m1, m2, m3, r1, r2, r3;
//--
class Character {
public:
stat statList[7] = {HP, ATK, DEF, MATK, MDEF, LUCK, MP};
string Name, Status[6];
Character() {
//only Monster array initialisation
}
Character (string n, int a, int b, int x, int y, int z, int i, int j) {
Name=n;
statList[0].value=a;
statList[1].value=b;
statList[2].value=x;
statList[3].value=y;
statList[4].value=z;
statList[5].value=i;
statList[6].value=j;
}
virtual int attack()=0;
};
class NPC: public Character {
//using Character::Character; //copies the constructor from Character
public:
NPC () {
}
NPC (string n, int a, int b, int x, int y, int z, int i, int j) {
Name=n;
statList[0].value=a;
statList[1].value=b;
statList[2].value=x;
statList[3].value=y;
statList[4].value=z;
statList[5].value=i;
statList[6].value=j;
}
int attack() {
int choice=rand()%4+1;
return choice;
}
};
//--
class Protag;
void warriorAbilities(Protag& p);
void mageAbilities(Protag& p);
void rogueAbilities(Protag& p);
//--
class Protag: public Character {
//using Character::Character;
public:
string charClass;
int level=1;
int battleExp=0;
skill ability[6];
int abilityCount;
Protag () {
}
Protag (string n, string c, int a, int b, int x, int y, int z, int i, int j) {
Name=n;
charClass=c;
statList[0].value=a;
statList[1].value=b;
statList[2].value=x;
statList[3].value=y;
statList[4].value=z;
statList[5].value=i;
statList[6].value=j;
}
int attack() {
return statList[1].value;
}
int magicAttack() {
return statList[3].value;
}
//TODO maybe optimise, having to use getAbilities and scrolling through already set abilities seems off
void getAbilities() {
if(charClass[0]=='w')
warriorAbilities(*this);
if(charClass[0]=='m')
mageAbilities(*this);
if(charClass[0]=='r')
rogueAbilities(*this);
}
};
//--
void warriorAbilities(Protag& p) {
int count = 1;
p.ability[0] = w1;
if(p.level > 5) {
p.ability[1] = w2;
count++;
}
if(p.level > 10) {
p.ability[2] = w3;
count++;
}
p.abilityCount = count;
};
void mageAbilities(Protag& p) {
int count = 1;
p.ability[0] = m1;
if(p.level > 5) {
p.ability[1] = m2;
count++;
}
if(p.level > 10) {
p.ability[2] = m3;
count++;
}
p.abilityCount = count;
};
void rogueAbilities(Protag& p) {
int count = 1;
p.ability[0] = r1;
if(p.level > 5) {
p.ability[1] = r2;
count++;
}
if(p.level > 10) {
p.ability[2] = r3;
count++;
}
p.abilityCount = count;
};
//--
int monsterChoice; //for the monster attack function and allowing it to be accessed by the battleMechanic() function
class Monster: public Character {
//using Character::Character;
public:
Monster () {
}
Monster (string n, int a, int b, int x, int y, int z, int i, int j) {
Name=n;
statList[0].value=a;
statList[1].value=b;
statList[2].value=x;
statList[3].value=y;
statList[4].value=z;
statList[5].value=i;
statList[6].value=j;
}
string mattack1="\0", mattack1effect="\0";
string mattack2="\0", mattack2effect="\0";
int exppoint=0;
//all new public members are initialised to null as they are properly initialised in finaliseMonsters()
void setValues(string ma1, string mae1, string ma2, string mae2, int exp) {
mattack1 = ma1;
mattack1effect = mae1;
mattack2 = ma2;
mattack2effect = mae2;
exppoint = exp;
}
int attack() {
int choice, damage=0;
srand(time(0));
choice=rand()%3+1;
monsterChoice=choice;
switch(choice) {
case 1:
cout<<Name<<" attacks."<<endl;
damage=statList[1].value;
break;
case 2:
cout<<Name<<" uses "<<mattack1<<endl;
damage=statList[3].value;
break;
case 3:
cout<<Name<<" uses "<<mattack2<<endl;
damage=statList[3].value;
break;
}
return damage;
}
};
//--
class Item {
public:
string itemName, Description;
int useCount;
Item() {
//only for inventory initialisation
}
Item(string i, string d, int u) {
itemName=i;
Description=d;
useCount=u;
}
void obtain() {
cout<<"You have obtained "<<itemName<<"."<<endl;
}
void clear() {
itemName="\0";
Description="\0";
}
};
//--
Protag mainchar("\0","\0",25,5,5,5,5,5,5);