cirno-puzzle/src/hero.cpp

61 lines
991 B
C++
Raw Normal View History

2020-02-19 12:50:09 -05:00
#include "hero.h"
2020-02-21 09:13:12 -05:00
Hero::Hero(coordinate position_x, coordinate position_y, int initial_charges) :
Entity(position_x, position_y),
2020-03-02 17:22:37 -05:00
hero_charges(initial_charges),
on_exit(false)
2020-02-19 12:50:09 -05: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 13:34:41 -05:00
if (hero_charges > 0)
{
2020-02-19 12:50:09 -05:00
--hero_charges;
return true;
}
return false;
}
2020-02-20 13:34:41 -05:00
2020-02-25 11:53:57 -05:00
void Hero::setCharges(int charges) noexcept
{
hero_charges = charges;
}
2020-02-21 09:13:12 -05:00
void Hero::move(const Direction &direction)
2020-02-20 13:34:41 -05:00
{
switch (direction)
{
2020-02-21 09:13:12 -05:00
case Direction::Up:
2020-02-20 13:34:41 -05:00
--pos_y; break;
2020-02-21 09:13:12 -05:00
case Direction::Down:
2020-02-20 13:34:41 -05:00
++pos_y; break;
2020-02-21 09:13:12 -05:00
case Direction::Left:
2020-02-20 13:34:41 -05:00
--pos_x; break;
2020-02-21 09:13:12 -05:00
case Direction::Right:
2020-02-20 13:34:41 -05:00
++pos_x; break;
2020-02-21 09:13:12 -05:00
case Direction::None:
2020-02-20 13:34:41 -05:00
break;
}
}
2020-02-21 09:13:12 -05:00
void Hero::reachExit() noexcept
{
on_exit = true;
}
bool Hero::onExit() const noexcept
2020-02-21 09:13:12 -05:00
{
return on_exit;
2020-02-21 09:13:12 -05:00
}