#include "Maze.h" #include "Player.h" #include "Exceptions/MalformedMaze.h" using game_exceptions::MalformedMaze; namespace game { Maze::Maze(const vector> play_field, const vector player_start_position): field(play_field), player_start_position(PositionVector{player_start_position[1], player_start_position[0]}) { if (!this->is_pos_free(this->player_start_position, false)) throw MalformedMaze("Player oob"); } bool Maze::was_player_killed_by_ghost(const Player& player) const { return this->field[player.get_pos().y][player.get_pos().x] == 'A'; } bool Maze::is_player_at_goal(const Player& player) const { return this->field[player.get_pos().y][player.get_pos().x] == 'Z'; } bool Maze::is_pos_free(const PositionVector& pos, const bool& player_has_key) const { if (pos.x < 0 || pos.y < 0 || pos.y > field.size() - 1 || pos.x > field[pos.y].size() - 1) return false; if (field[pos.y][pos.x] == '#') return false; if (field[pos.y][pos.x] == 'T') return player_has_key; return true; } void Maze::render(const Player& player) const { for (int y = 0; y < field.size(); ++y) { for (int x = 0; x < field[y].size(); ++x) { if (y == player.get_pos().y && x == player.get_pos().x) cout << "S"; else cout << field[y][x]; cout << " "; } cout << "\n"; } } char Maze::get_field(const PositionVector& pos) const { return this->field[pos.y][pos.x]; } void Maze::update_field(const PositionVector& pos, const char& target) { this->field[pos.y][pos.x] = target; } PositionVector Maze::get_player_start_position() const { return this->player_start_position; } } // game