cirno-puzzle/hero.cpp

52 lines
853 B
C++
Raw Normal View History

2020-02-19 18:50:09 +01:00
#include "hero.h"
2020-02-20 19:34:41 +01:00
Hero::Hero(int position_x, int position_y, int initial_charges) :
hero_charges(initial_charges),
pos_x(position_x),
pos_y(position_y)
2020-02-19 18:50:09 +01:00
{}
void Hero::refillCharges(int append_charges)
{
hero_charges += append_charges;
}
int Hero::charges() const noexcept
{
return hero_charges;
}
bool Hero::useCharge()
{
2020-02-20 19:34:41 +01:00
if (hero_charges > 0)
{
2020-02-19 18:50:09 +01:00
--hero_charges;
return true;
}
return false;
}
2020-02-20 19:34:41 +01:00
void Hero::position(int &x, int &y) const noexcept
{
x = pos_x;
y = pos_y;
}
void Hero::move(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;
}
}