#include "std_lib_inc.h" #include "Player.h" #include "Maze.h" #include "Exceptions/MovementNotPossible.h" using game_exceptions::MovementNotPossible; namespace game { Player::Player(const int target_x, const int target_y): pos(target_x, target_y), keys_in_inventory(0) { } Player::Player(const PositionVector pos) : pos(pos), keys_in_inventory(0) { } PositionVector Player::get_pos() const { return this->pos; } void Player::update_position(const PositionVector& target) { this->pos = target; } Maze Player::move(Maze& maze, const PositionVector& move_vector) { const PositionVector target_position = PositionVector(this->get_pos().x + move_vector.x, this->get_pos().y + move_vector.y); if (maze.is_pos_free(target_position, this->has_key_available())) { this->update_position(target_position); switch (maze.get_field(target_position)) { case 'K': ++this->keys_in_inventory; maze.update_field(target_position, '.'); break; case 'T': --this->keys_in_inventory; maze.update_field(target_position, '.'); break; default: ; } } else throw MovementNotPossible("Bewegung nicht moeglich!"); return maze; } bool Player::has_key_available() const { return this->keys_in_inventory > 0; } } // game