cirno-puzzle/hero.cpp

58 lines
973 B
C++
Raw Normal View History

2020-02-19 18:50:09 +01:00
#include "hero.h"
2020-02-21 15:13:12 +01:00
Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) :
2020-02-20 19:34:41 +01:00
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
2020-02-21 15:13:12 +01:00
void Hero::position(coordinate &x, coordinate &y) const noexcept
2020-02-20 19:34:41 +01:00
{
x = pos_x;
y = pos_y;
}
2020-02-21 15:13:12 +01:00
void Hero::move(const Direction &direction)
2020-02-20 19:34:41 +01:00
{
switch (direction)
{
2020-02-21 15:13:12 +01:00
case Direction::Up:
2020-02-20 19:34:41 +01:00
--pos_y; break;
2020-02-21 15:13:12 +01:00
case Direction::Down:
2020-02-20 19:34:41 +01:00
++pos_y; break;
2020-02-21 15:13:12 +01:00
case Direction::Left:
2020-02-20 19:34:41 +01:00
--pos_x; break;
2020-02-21 15:13:12 +01:00
case Direction::Right:
2020-02-20 19:34:41 +01:00
++pos_x; break;
2020-02-21 15:13:12 +01:00
case Direction::None:
2020-02-20 19:34:41 +01:00
break;
}
}
2020-02-21 15:13:12 +01:00
void Hero::setPosition(coordinate x, coordinate y)
{
pos_x = x;
pos_y = y;
}