-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwizard.cpp
More file actions
71 lines (62 loc) · 2.05 KB
/
wizard.cpp
File metadata and controls
71 lines (62 loc) · 2.05 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
#include "wizard.h"
Wizard::Wizard(string n, string r, int l, int h, int m){
SetName(n);
SetRace(r);
SetLevel(l);
SetHealth(h);
mana = m;
}
Wizard::~Wizard(){}
int Wizard::getMana() const {return mana;}
void Wizard::SetMana(int m) {mana = m;}
int Wizard::AddSpell(string n, int d, int m){
spell nSpell;
nSpell.name = n;
nSpell.damage = d;
nSpell.mana_cost = m;
if(numOfSpells < 10){
spells[numOfSpells++] = nSpell;
}
else cout << "Spell limits reached!" << endl;
return numOfSpells;
}
void Wizard::Attack(Character *target){
if(numOfSpells == 0){
cout << "This wizard has no spells!" << endl;
}
else if(mana < spells[0].mana_cost){
cout << "Insufficient mana points!" << endl;
}
else{
mana -= spells[0].mana_cost;
target->SetHealth(target->getHealth() - spells[0].damage);
cout << getName() << " attacked " << target->getName() << " with spell: " << spells[0].name << ", dealing " << spells[0].damage << " damage." << endl;
}
}
void Wizard::Attack(Character *target, int spell_num){
if(spell_num < 0 || spell_num >= numOfSpells){
cout << "Invalid spell number!" << endl;
}
else if(numOfSpells == 0){
cout << "This wizard has no spells!" << endl;
}
else if(mana < spells[spell_num].mana_cost){
cout << "Insufficient mana points!" << endl;
}
else{
mana -= spells[spell_num].mana_cost;
target->SetHealth(target->getHealth() - spells[spell_num].damage);
cout << getName() << " attacked " << target->getName() << " with spell: " << spells[spell_num].name << ", dealing " << spells[spell_num].damage << " damage." << endl;
}
}
void Wizard::Print(){
cout << "Character Status: " << endl;
cout << "Name: " << getName() << endl;
cout << "Race: " << getRace() << endl;
cout << "Level: " << getLevel() << endl;
cout << "Health: " << getHealth() << endl;
cout << "Spells: " << endl;
for(int a = 0; a < numOfSpells; a++){
cout << spells[a].name << endl;
}
}