diff options
Diffstat (limited to 'src/games/minesweeper')
| -rw-r--r-- | src/games/minesweeper/Minesweeper.cpp | 40 | ||||
| -rw-r--r-- | src/games/minesweeper/Minesweeper.hpp | 7 | 
2 files changed, 20 insertions, 27 deletions
diff --git a/src/games/minesweeper/Minesweeper.cpp b/src/games/minesweeper/Minesweeper.cpp index 2a69e4d..a091491 100644 --- a/src/games/minesweeper/Minesweeper.cpp +++ b/src/games/minesweeper/Minesweeper.cpp @@ -1,4 +1,3 @@ -#include "games/Game.hpp"  #include <games/minesweeper/Minesweeper.hpp>  #include <renderer/Renderer.hpp> @@ -6,10 +5,15 @@  #include <algorithm>  #include <random> -#include <cstdio> -// Todo: winning condition (maybe: total_cells - uncovered_cells = mine_count) +// Todo:  +// - First click may not be a mine! +// - Show current time spent +// - Show current flags/mines left +// - Permit uncovering of flagged cell +// - Game Over: Winning Condition (maybe: total_cells - uncovered_cells == mine_count) +// - Game Over: Show Highscore for selected difficulty  static constexpr Color s_mine_count_colors[8] = { @@ -25,11 +29,8 @@ static constexpr Color s_mine_count_colors[8] = {  Minesweeper::Minesweeper() +    : m_font{s_dejavu_sans_filepath, 22}  { -    bool font_init = m_font.Init(s_font_filepath, 22); -    if (!font_init) { -        printf("m_font.Init(...) failed\n"); -    }  }  void @@ -148,7 +149,7 @@ Minesweeper::Update(std::vector<SDL_Event>& events)      if (m_game_status == game_paused) {          DrawBoard(); -        DrawGamePausedMenu(); +        DrawDefaultGamePausedMenu();      }      else if (m_game_status == game_starting) {          DrawStartMenu(); @@ -158,7 +159,7 @@ Minesweeper::Update(std::vector<SDL_Event>& events)      }      else if (m_game_status == game_over) {          DrawBoard(); -        DrawGameOverMenu(); +        DrawDefaultGameOverMenu();      }      return true; @@ -370,7 +371,7 @@ Minesweeper::DrawBoard()              bool is_mine = IsMine(x, y);              if (is_covered) { -                g_renderer.PushRectangle(cell_rect, 0.0f, covered_cell_color); +                g_renderer.PushRectangle(cell_rect, covered_cell_color, 0.0f);                  if (is_flagged) { @@ -385,7 +386,7 @@ Minesweeper::DrawBoard()                          flag_pos.x + flag_size.x,                          flag_pos.y + flag_size.y,                      }; -                    g_renderer.PushRectangle(flag_rect, flag_pos.z, flag_color); +                    g_renderer.PushRectangle(flag_rect, flag_color, flag_pos.z);                  }              }              else { @@ -401,26 +402,21 @@ Minesweeper::DrawBoard()                          mine_pos.x + m_cell_inner_size.x,                          mine_pos.y + m_cell_inner_size.y,                      }; -                    g_renderer.PushRectangle(mine_rect, mine_pos.z, mine_color); +                    g_renderer.PushRectangle(mine_rect, mine_color, mine_pos.z);                  }                  else { -                    g_renderer.PushRectangle(cell_rect, 0.0f, uncovered_cell_color); +                    g_renderer.PushRectangle(cell_rect, uncovered_cell_color, 0.0f); -                    // Todo: Figure out how to scale this properly. -                    //       256.0f is a random number that just works for now.                      V3F32 mine_count_pos = { -                        256.0f * cell_pos.x, -                        256.0f * cell_pos.y, -                        256.0f +                        cell_pos.x, +                        cell_pos.y, +                        1.0f                      };                      int32_t mine_count = m_adjacent_mine_counts[y*m_grid_width + x];                      if (mine_count > 0) {                          Color color = s_mine_count_colors[mine_count-1];                          Glyph& glyph = m_font.GetGlyph('0' + (char32_t)mine_count); -                        g_renderer.PushAlphaBitmap( -                                                   glyph.bitmap, -                                                   mine_count_pos, -                                                   color); +                        g_renderer.PushAlphaBitmap(glyph.bitmap, mine_count_pos, color);                      }                  }              } diff --git a/src/games/minesweeper/Minesweeper.hpp b/src/games/minesweeper/Minesweeper.hpp index 24672f0..fbdcb30 100644 --- a/src/games/minesweeper/Minesweeper.hpp +++ b/src/games/minesweeper/Minesweeper.hpp @@ -4,8 +4,6 @@  #include <common/math.hpp>  #include <common/Font.hpp> -#include <array> -  class Minesweeper : public Game {  public: @@ -21,11 +19,11 @@ public:      bool Update(std::vector<SDL_Event>& events) override; + +private:      void ProcessEventDuringPause(SDL_Event& event);      void ProcessEventDuringResume(SDL_Event& event); - -private:      void Reset(Difficulty Difficulty);      void InitIsMineBitmap(int32_t mine_count);      void InitAdjacentMineCounters(); @@ -50,7 +48,6 @@ private:  private:      static constexpr int32_t max_map_height = 32;      static constexpr int32_t max_map_width = 32; -    static constexpr const char* s_font_filepath = "./fonts/dejavu_ttf/DejaVuSans.ttf";  private:  | 
