From d7eb5c7f4d300ad498efd3bb893a84608ac4b35c Mon Sep 17 00:00:00 2001 From: Reimar Date: Mon, 27 Oct 2025 12:35:48 +0100 Subject: [PATCH] Use enum class --- src/Map.cpp | 16 ++++++++-------- src/Tile.hpp | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Map.cpp b/src/Map.cpp index 11ab361..c472f1e 100644 --- a/src/Map.cpp +++ b/src/Map.cpp @@ -4,7 +4,7 @@ Map::Map(GameRenderer *renderer, int tile_size) : renderer(renderer), tile_size(tile_size), - tiles(renderer->screen_width / tile_size, std::vector(renderer->screen_height / tile_size, grass)), + tiles(renderer->screen_width / tile_size, std::vector(renderer->screen_height / tile_size, Tile::grass)), tile_offset_x(-renderer->screen_width / tile_size / 2), tile_offset_y(-renderer->screen_height / tile_size / 2) { @@ -16,7 +16,7 @@ Map::Map(GameRenderer *renderer, int tile_size) : for (int x = 0; x < tiles.size(); x++) { if (rand() % 2 == 0) y += rand() % 3 - 1; - tiles[x][y] = path; + tiles[x][y] = Tile::path; } // Create vertical starting path @@ -24,22 +24,22 @@ Map::Map(GameRenderer *renderer, int tile_size) : for (int y = 0; y < tiles[x].size(); y++) { if (rand() % 2 == 0) x += rand() % 3 - 1; - tiles[x][y] = path; + tiles[x][y] = Tile::path; } } std::vector Map::generate_tiles(std::vector prev_tiles) const { - std::vector new_tiles = std::vector(prev_tiles.size(), grass); + std::vector new_tiles = std::vector(prev_tiles.size(), Tile::grass); int path_idx = 0; for (int i = 0; i < prev_tiles.size(); i++) { - if (prev_tiles[i] == path) path_idx = i; + if (prev_tiles[i] == Tile::path) path_idx = i; } if (rand() % 2 == 0) path_idx += rand() % 3 - 1; - new_tiles[path_idx] = path; + new_tiles[path_idx] = Tile::path; return new_tiles; } @@ -103,8 +103,8 @@ void Map::draw(int player_x, int player_y) const } switch (tiles[tile_x][tile_y]) { - case grass: renderer->draw_sprite(grass_sprite, screen_x, screen_y); break; - case path: renderer->draw_sprite(path_sprite, screen_x, screen_y); break; + case Tile::grass: renderer->draw_sprite(grass_sprite, screen_x, screen_y); break; + case Tile::path: renderer->draw_sprite(path_sprite, screen_x, screen_y); break; } } } diff --git a/src/Tile.hpp b/src/Tile.hpp index cef7809..42cf067 100644 --- a/src/Tile.hpp +++ b/src/Tile.hpp @@ -1,7 +1,7 @@ #ifndef TILE_HPP #define TILE_HPP -enum Tile +enum class Tile { grass, path,