aboutsummaryrefslogtreecommitdiff
path: root/src/games/minesweeper/Minesweeper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/games/minesweeper/Minesweeper.cpp')
-rw-r--r--src/games/minesweeper/Minesweeper.cpp40
1 files changed, 18 insertions, 22 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);
}
}
}