#include "cell.h" #include "hero.h" #include "level.h" #define UNUSED(expr) (void)(expr); Cell::Cell(coordinate cell_x, coordinate cell_y, const sf::Color &color) : Entity(cell_x, cell_y), cell_color(color) {} Cell::~Cell() {} sf::Color Cell::color() const noexcept { return cell_color; } /////////////////////////////////////// PassableCell::PassableCell(coordinate cell_x, coordinate cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color) {} PassableCell::~PassableCell() {} bool PassableCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { UNUSED(hero) UNUSED(level) // Hero just moves on. return true; } /////////////////////////////////////// WaterCell::WaterCell(coordinate cell_x, coordinate cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color) {} WaterCell::~WaterCell() {} bool WaterCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { // Try to use one charge to place a bridge if (hero->useCharge()) { level->placeBridge(pos_x, pos_y); return true; } // If hero doesn't have enough charges, we move Hero back return false; } /////////////////////////////////////// WallCell::WallCell(coordinate cell_x, coordinate cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color) {} WallCell::~WallCell() {} bool WallCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { UNUSED(hero) UNUSED(level) // Hero never passes this cell. return false; } /////////////////////////////////////// ChargeCell::ChargeCell(coordinate cell_x, coordinate cell_y, int has_charges, const sf::Color &color) : Cell(cell_x, cell_y, color), cell_charges(has_charges) {} ChargeCell::~ChargeCell() {} bool ChargeCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { // Hero picks up the charge; remove it from the map hero->refillCharges(cell_charges); level->removeCharge(pos_x, pos_y); return true; } /////////////////////////////////////// ExitCell::ExitCell(coordinate cell_x, coordinate cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color) {} ExitCell::~ExitCell() {} bool ExitCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { UNUSED(level) // Level is over. hero->reachExit(); return true; } /////////////////////////////////////// TeleportCell::TeleportCell(coordinate cell_x, coordinate cell_y, coordinate new_cell_x, coordinate new_cell_y, const sf::Color &color) : Cell(cell_x, cell_y, color), new_x(new_cell_x), new_y(new_cell_y) {} TeleportCell::~TeleportCell() {} bool TeleportCell::onMovingTo(HeroPtr &hero, LevelPtr &level) { UNUSED(level) // Hero jumps into teleport! hero->setPosition(new_x, new_y); return true; }