aboutsummaryrefslogtreecommitdiff
path: root/src/games/minesweeper/Minesweeper.cpp
diff options
context:
space:
mode:
authorfschildt <florian.schildt@protonmail.com>2025-12-11 02:26:56 +0100
committerfschildt <florian.schildt@protonmail.com>2025-12-11 02:56:04 +0100
commit6fffbbed46b903223f752faee7bbb870557665c9 (patch)
tree11c52ccd5fc3a6e3bae142052fa54c49bc6ba853 /src/games/minesweeper/Minesweeper.cpp
parent69f46d34e9c6a25c63668423fd984d07c1f099a3 (diff)
refactor Game.hpp, add unfinished pong
Diffstat (limited to 'src/games/minesweeper/Minesweeper.cpp')
-rw-r--r--src/games/minesweeper/Minesweeper.cpp81
1 files changed, 17 insertions, 64 deletions
diff --git a/src/games/minesweeper/Minesweeper.cpp b/src/games/minesweeper/Minesweeper.cpp
index 3638af8..a2738a2 100644
--- a/src/games/minesweeper/Minesweeper.cpp
+++ b/src/games/minesweeper/Minesweeper.cpp
@@ -30,15 +30,15 @@ Minesweeper::Minesweeper()
}
void
-Minesweeper::Reset(Difficulty difficulty)
+Minesweeper::Start()
{
m_cells_uncovered = 0;
- if (difficulty == beginner) {
+ if (m_difficulty == beginner) {
m_grid_width = 8;
m_grid_height = 8;
m_mine_count = 10;
}
- else if(difficulty == intermediate) {
+ else if (m_difficulty == intermediate) {
m_grid_width = 16;
m_grid_height = 16;
m_mine_count = 40;
@@ -64,6 +64,8 @@ Minesweeper::Reset(Difficulty difficulty)
memset(m_is_flagged_bitmap, 0 , sizeof(m_is_flagged_bitmap));
InitIsMineBitmap();
InitAdjacentMineCounters();
+
+ m_game_status = game_resume;
}
void
@@ -122,66 +124,13 @@ Minesweeper::IsWon()
return is_won;
}
-bool
-Minesweeper::Update(std::vector<SDL_Event>& events)
-{
- g_renderer.SetCameraSize(4.0f, 3.0f);
- g_renderer.SetClearColor({0.3f, 0.2f, 0.3f});
-
- for (SDL_Event &event : events) {
- if (m_game_status == game_exit) {
- return false;
- }
- else if (m_game_status == game_paused) {
- ProcessEventDuringPause(event);
- }
- else if (m_game_status== game_resuming) {
- ProcessEventDuringResume(event);
- }
- }
- if (m_game_status == game_exit) {
- return false;
- }
-
- if (m_game_status == game_paused) {
- DrawBoard();
- DrawDefaultGamePausedMenu();
- }
- else if (m_game_status == game_starting) {
- DrawStartMenu();
- }
- else if (m_game_status == game_resuming) {
- DrawBoard();
- }
- else if (m_game_status == game_over) {
- DrawBoard();
- DrawGameOverMenu();
- }
-
- return true;
-}
-
void
-Minesweeper::ProcessEventDuringPause(SDL_Event &event)
+Minesweeper::ProcessEvent(SDL_Event& event)
{
switch (event.type) {
case SDL_EVENT_KEY_DOWN: {
if (event.key.key == SDLK_ESCAPE) {
- m_game_status = game_resuming;
- }
- } break;
-
- default:;
- }
-}
-
-void
-Minesweeper::ProcessEventDuringResume(SDL_Event &event)
-{
- switch (event.type) {
- case SDL_EVENT_KEY_DOWN: {
- if (event.key.key == SDLK_ESCAPE) {
- m_game_status = game_paused;
+ m_game_status = game_pause;
}
} break;
@@ -237,6 +186,11 @@ Minesweeper::ProcessEventDuringResume(SDL_Event &event)
}
void
+Minesweeper::FinishUpdate(float dt)
+{
+}
+
+void
Minesweeper::Uncover(int32_t x, int32_t y)
{
if (x < 0) return;
@@ -321,7 +275,7 @@ Minesweeper::ScreenPosToViewPos(V2F32 screen_pos)
}
void
-Minesweeper::DrawBoard()
+Minesweeper::Draw()
{
uint32_t z = 1;
Color covered_cell_color {0.6f, 0.6f, 0.6f};
@@ -403,9 +357,9 @@ Minesweeper::DrawBoard()
}
void
-Minesweeper::DrawStartMenu()
+Minesweeper::DrawGameStartMenu()
{
- ImGui::Begin("MinesweeperStart");
+ ImGui::Begin("MinesweeperGameStartMenu");
if (ImGui::RadioButton("beginner", m_difficulty == beginner ? true : false)) {
m_difficulty = beginner;
}
@@ -416,8 +370,7 @@ Minesweeper::DrawStartMenu()
m_difficulty = expert;
}
if (ImGui::Button("Start")) {
- Reset(m_difficulty);
- m_game_status = game_resuming;
+ Start();
}
if (ImGui::Button("Exit")) {
m_game_status = game_exit;
@@ -436,7 +389,7 @@ Minesweeper::DrawGameOverMenu()
ImGui::Text("You Lost.");
}
if (ImGui::Button("Play Again")) {
- m_game_status = game_starting;
+ m_game_status = game_start;
}
if (ImGui::Button("Exit")) {
m_game_status = game_exit;