-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMonster.cpp
125 lines (107 loc) · 2.6 KB
/
Monster.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
#include "Game.h"
#include "Character.h"
#include "Magic.h"
using namespace std;
void Monster::collide(Map *map, Knight *target)
{
target->recieveDamage(_damage);
}
void Monster::collide(Map *map, Princess *target)
{
target->recieveDamage(_damage);
}
void Monster::move(Map *map)
{
Vec2i newCoords = map->calcShortestPath(map->getHero()->coordinates(), _coords);
collide(map, map->getActor(newCoords));
map->setHasActed(_coords);
}
void Dragon::move(Map *map)
{
for (int i = -1; i < 1; ++i)
{
for (int j = -1; j < 1; ++j)
{
if (map->isHero(_coords + Vec2i(i, j)))
{
collide(map, map->getActor(_coords + Vec2i(i, j)));
return;
}
}
}
_direction = Vec2i(rand() % 2, rand() % 2);
if (map->isValidCell(newCoordinates()))
collide(map, map->getActor(newCoordinates()));
map->setHasActed(_coords);
}
void Zombie::recieveDamage(int damage)
{
_hp -= damage;
Game::getInstance().pushLogMessage("Zombie received " + to_string(damage) + " damage.\n");
Game::getInstance().pushLogMessage("Zombie has " + to_string(_hp) + " hp left.\n");
if (isDead())
{
Game::getInstance().pushLogMessage("Zombie died.\n");
}
}
void Zombie::heal(int ammount)
{
_hp += ammount;
if (_hp > ZOMBIE_HP)
_hp = ZOMBIE_HP;
}
void Dragon::heal(int ammount)
{
_hp += ammount;
if (_hp > DRAGON_HP)
_hp = DRAGON_HP;
}
void Dragon::recieveDamage(int damage)
{
_hp -= damage;
Game::getInstance().pushLogMessage("Dragon received " + to_string(damage) + " damage.\n");
Game::getInstance().pushLogMessage("Dragon has " + to_string(_hp) + " hp left.\n");
if (isDead())
{
Game::getInstance().pushLogMessage("Dragon died.\n");
}
}
void Wizard::recieveDamage(int damage)
{
_hp -= damage;
Game::getInstance().pushLogMessage("Wizard received " + to_string(damage) + " damage.\n");
Game::getInstance().pushLogMessage("Wizard has " + to_string(_hp) + " hp left.\n");
if (isDead())
{
Game::getInstance().pushLogMessage("Wizard died.\n");
}
}
void Wizard::heal(int ammount)
{
_hp += ammount;
if (_hp > WIZARD_HP)
_hp = DRAGON_HP;
}
void Wizard::move(Map *map)
{
_mana += WIZARD_MANA_REGEN;
int curMove = rand() % 2;
if (curMove == 0)
{
if (_mana >= FIREBALL_MANA_COST)
{
Vec2i fireBallDir = DIRECTIONS[rand() % 4];
Vec2i fireBallCoords = _coords + fireBallDir;
if (map->isEmptyCell(fireBallCoords))
map->replace(fireBallCoords, new FireBall(fireBallCoords, fireBallDir, FIREBALL_DAMAGE));
_mana -= FIREBALL_MANA_COST;
}
}
if (curMove == 1)
{
_direction = DIRECTIONS[rand() % 4];
if (map->isValidCell(newCoordinates()))
collide(map, map->getActor(newCoordinates()));
}
map->setHasActed(_coords);
}