From 5e5ea14693cc9443d73cc5dcc736e369fb341b9e Mon Sep 17 00:00:00 2001
From: NaiJi <naijiworld@protonmail.com>
Date: Fri, 21 Feb 2020 17:20:40 +0300
Subject: [PATCH] Replace raw chars with CellType enum variables

---
 game.cpp  |  4 ++--
 level.cpp | 27 +++++++++++++--------------
 level.h   | 14 +++++++++++---
 3 files changed, 26 insertions(+), 19 deletions(-)

diff --git a/game.cpp b/game.cpp
index ec1d9dc..34b5c98 100644
--- a/game.cpp
+++ b/game.cpp
@@ -90,7 +90,7 @@ void Game::onMoving(sf::Keyboard::Key &key)
     //////////////////////////
 
     // If the following cell is water
-    if (level->isCellOfType(attempt_x, attempt_y, '.'))
+    if (level->isCellOfType(attempt_x, attempt_y, CellType::Water))
     {
         // Try to use one charge to place a bridge
         if (hero->useCharge())
@@ -103,7 +103,7 @@ void Game::onMoving(sf::Keyboard::Key &key)
     //////////////////////////
 
     // If the following cell is a charge
-    if (level->isCellOfType(attempt_x, attempt_y, '$'))
+    if (level->isCellOfType(attempt_x, attempt_y, CellType::Charge))
     {
         // Hero picks up the charge; remove it from the map
         hero->refillCharges(1);
diff --git a/level.cpp b/level.cpp
index 86de50c..bf2e317 100644
--- a/level.cpp
+++ b/level.cpp
@@ -5,34 +5,33 @@ Level::Level()
     // Fill the level with water
     for (Row &row : map)
     {
-        for (char &cell : row)
-            cell = '.';
+        for (CellType &cell : row)
+            cell = CellType::Water;
     }
 
     // Temporary mock
 
-    // Ground
-    map[1][2] = '-';
-    map[1][3] = '-';
-    map[1][4] = '-';
-    map[2][2] = '-';
-    map[3][2] = '-';
-    map[3][3] = '-';
-    // Charge
-    map[2][3] = '$';
+    map[1][2] = CellType::Ground;
+    map[1][3] = CellType::Ground;
+    map[1][4] = CellType::Ground;
+    map[2][2] = CellType::Ground;
+    map[3][2] = CellType::Ground;
+    map[3][3] = CellType::Ground;
+
+    map[2][3] = CellType::Charge;
 }
 
 void Level::placeBridge(coordinate x, coordinate y)
 {
-    map[x][y] = static_cast<char>(177);
+    map[x][y] = CellType::Bridge;
 }
 
-bool Level::isCellOfType(coordinate x, coordinate y, char type) const
+bool Level::isCellOfType(coordinate x, coordinate y, CellType type) const
 {
     return (map[x][y] == type);
 }
 
 void Level::removeCharge(coordinate x, coordinate y)
 {
-    map[x][y] = '-';
+    map[x][y] = CellType::Ground;
 }
diff --git a/level.h b/level.h
index cf3f83f..d313037 100644
--- a/level.h
+++ b/level.h
@@ -3,13 +3,21 @@
 
 #include <array>
 
+enum CellType
+{
+    Water  = '.',
+    Ground = '-',
+    Charge = '$',
+    Bridge = char(177)
+};
+
 using coordinate = unsigned int;
 constexpr coordinate side = 32;
 
-using Row = std::array<char, side>;
+using Row = std::array<CellType, side>;
 using Map = std::array<Row, side>;
 
-/// Abstraction over 2D array to quickly get access to unchangable level cells
+/// Abstraction over 2D array to quickly get access to level cells
 class Level
 {
 private:
@@ -25,7 +33,7 @@ public:
     Map& mapArray() const;
 
     /// Is the following cell has requested type
-    bool isCellOfType(coordinate x, coordinate y, char type) const;
+    bool isCellOfType(coordinate x, coordinate y, CellType type) const;
 
     /// Replace a charge cell with a ground cell
     void removeCharge(coordinate x, coordinate y);