-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.cpp
67 lines (57 loc) · 1.39 KB
/
Player.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
#include "Player.h"
Player::Player() {}
Player::~Player() {
for (auto spell : spellList) {
delete spell;
}
}
bool Player::FindSpell(String& spell) {
int upper = spellList.size() - 1;
int lower = 0;
int target;
String temp;
while (lower <= upper) {
target = (upper + lower) / 2;
temp = spellList[target]->GetName();
temp.ToLower();
if (temp == spell) return true;
if (temp < spell) lower = target + 1;
if (temp > spell) upper = target - 1;
}
return false;
}
Spell* Player::CastSpell(String& spell)
{
int upper = spellList.size() - 1;
int lower = 0;
int target;
String temp;
while (lower <= upper) {
target = (upper + lower) / 2;
temp = spellList[target]->GetName();
temp.ToLower();
if (temp == spell) return spellList[target];
if (temp < spell) lower = target + 1;
if (temp > spell) upper = target - 1;
}
return nullptr;
}
std::vector<Spell*> Player::GetSpellList() {
return this->spellList;
}
void Player::SpellList(){
for (int i = 0; i < spellList.size(); i++) {
std::cout << "\t\t" << spellList[i]->GetName() << " | " << spellList[i]->GetDamage() << " damage" << "\n";
}
}
void Player::AddSpell(Spell* spell) {
spellList.push_back(spell);
if (spellList.size() >= 2) std::sort(spellList.begin(), spellList.end(), Spell::Compare);
}
void Player::SetPos(Vec2 pos) {
playerPos.x = pos.x;
playerPos.y = pos.y;
}
Vec2 Player::GetPos() const {
return playerPos;
}