From 8e101f8bfd995321ac08a16fea9a171b549a0ae4 Mon Sep 17 00:00:00 2001 From: Steph Enders Date: Sat, 17 Dec 2022 11:04:20 -0500 Subject: Support doors with keys Add initial support for doors and keys via pre-defined mappings: k || d ------ 1 -> a 2 -> b 3 -> c 4 -> d Any key can open any door of its mapping, but is spent once used. May require additional testing --- src/Level.h | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/Level.h') diff --git a/src/Level.h b/src/Level.h index 7b25d0b..7c2c74b 100644 --- a/src/Level.h +++ b/src/Level.h @@ -39,8 +39,14 @@ static const char TREASURE_TKN = 't'; static const char ENEMY_TKN = 'e'; static const char BLANK_SPACE = '\0'; static const char WALL_SPACE = '#'; +static const char KEY_TKN_START = '1'; // inclusive (1, 2, 3, 4) +static const char KEY_TKN_END = '4'; // inclusive (1, 2, 3, 4) +static const char DOOR_TKN_START = 'a'; // inclusive (a, b, c, d) +static const char DOOR_TKN_END = 'd'; // inclusive (a, b, c, d) +static const char KEY_DOOR_MAPPING[4] = {'a', 'b', 'c', 'd'}; struct Pos { + char token; int id; int x; int y; @@ -54,6 +60,8 @@ public: ~Level() = default; void load(); bool playerCanStep(int dx, int dy) const; + bool tryDoor(int x, int y) const; + bool isDoor(int x, int y) const; int getEnemyIndex(int id); bool enemyCanStep(const Pos &pos, int dx, int dy) const; void reset(); @@ -64,8 +72,11 @@ public: std::vector> map; // source copy of map std::vector displayMap; Pos player; + std::vector heldKeys; std::vector enemyPositions; std::vector treasurePositions; + std::vector doorPositions; + std::vector keyPositions; private: int idCounter = 1; // defaults at 1 (player always 0) -- cgit v1.2.3-54-g00ecf