-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKnight.cpp
60 lines (50 loc) · 1.24 KB
/
Knight.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
#include <conio.h>
#include "Game.h"
#include "Character.h"
using namespace std;
Knight::Knight(Vec2i coords, int hp, char symb, int damage) : Character(coords, hp, symb, damage)
{
_directions['s'] = Vec2i(0, 1);
_directions['w'] = Vec2i(0, -1);
_directions['a'] = Vec2i(-1, 0);
_directions['d'] = Vec2i(1, 0);
}
void Knight::recieveDamage(int damage)
{
_hp -= damage;
Game::getInstance().pushLogMessage("You received " + to_string(damage) + " damage\n");
if (isDead())
Game::getInstance().setGameState(Game::GameState::exiting);
}
void Knight::setDirection(char dir)
{
auto it = _directions.find(dir);
if (it != _directions.end())
_direction = it->second;
else
_direction = Vec2i(0, 0); //default
}
void Knight::collide(Map *map, Monster *target)
{
target->recieveDamage(_damage);
if (target->isDead())
map->clearCell(target->coordinates());
}
void Knight::collide(Map *map, Princess *target)
{
Game::getInstance().setGameState(Game::GameState::exiting);
}
void Knight::move(Map *map)
{
char dir = _getch();
setDirection(dir);
if (map->isValidCell(newCoordinates()))
collide(map, map->getActor(newCoordinates()));
map->setHasActed(_coords);
}
void Knight::heal(int ammount)
{
_hp += ammount;
if (_hp > KNIGHT_HP)
_hp = KNIGHT_HP;
}