58 lines
973 B
C++
58 lines
973 B
C++
#include "hero.h"
|
|
|
|
Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) :
|
|
hero_charges(initial_charges),
|
|
pos_x(position_x),
|
|
pos_y(position_y)
|
|
{}
|
|
|
|
void Hero::refillCharges(int append_charges)
|
|
{
|
|
hero_charges += append_charges;
|
|
}
|
|
|
|
int Hero::charges() const noexcept
|
|
{
|
|
return hero_charges;
|
|
}
|
|
|
|
bool Hero::useCharge()
|
|
{
|
|
if (hero_charges > 0)
|
|
{
|
|
--hero_charges;
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void Hero::position(coordinate &x, coordinate &y) const noexcept
|
|
{
|
|
x = pos_x;
|
|
y = pos_y;
|
|
}
|
|
|
|
void Hero::move(const Direction &direction)
|
|
{
|
|
switch (direction)
|
|
{
|
|
case Direction::Up:
|
|
--pos_y; break;
|
|
case Direction::Down:
|
|
++pos_y; break;
|
|
case Direction::Left:
|
|
--pos_x; break;
|
|
case Direction::Right:
|
|
++pos_x; break;
|
|
case Direction::None:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void Hero::setPosition(coordinate x, coordinate y)
|
|
{
|
|
pos_x = x;
|
|
pos_y = y;
|
|
}
|