diff options
Diffstat (limited to 'src/games/minesweeper/Minesweeper.hpp')
| -rw-r--r-- | src/games/minesweeper/Minesweeper.hpp | 109 | 
1 files changed, 62 insertions, 47 deletions
diff --git a/src/games/minesweeper/Minesweeper.hpp b/src/games/minesweeper/Minesweeper.hpp index b081806..b89743e 100644 --- a/src/games/minesweeper/Minesweeper.hpp +++ b/src/games/minesweeper/Minesweeper.hpp @@ -1,5 +1,7 @@  #pragma once +#include "imgui.h" +#include "renderer/RenderGroup.hpp"  #include <games/Game.hpp>  #include <common/Font.hpp> @@ -18,73 +20,86 @@ namespace std {  } -enum class MinesweeperRunState { -    Resume, -    Pause, -    GameOver, -    Restart, -    Exit -}; -  class Minesweeper : public Game { -    public: -        Minesweeper(); -        ~Minesweeper() = default; +public: +    enum RunState { +        start_menu, +        pause, +        resume, +        game_over, +        exit +    }; + +    enum Difficulty { +        beginner, +        intermediate, +        expert +    }; + +public: +    Minesweeper(RenderGroup& render_group); +    ~Minesweeper() = default; + +    bool Update(std::vector<SDL_Event>& events) override; + +    void ProcessEventDuringPause(SDL_Event& event); +    void ProcessEventDuringResume(SDL_Event& event); -        bool Update(std::vector<SDL_Event> &events, RenderGroup &render_group) override; -        void ProcessEventDuringPause(SDL_Event &event, RenderGroup &render_group); -        void ProcessEventDuringResume(SDL_Event &event, RenderGroup &render_group); +private: +    void Reset(Difficulty Difficulty); +    void InitIsMineBitmap(int32_t mine_count); +    void InitAdjacentMineCounters(); +    void UncoverMines(); +    void Uncover(int32_t x, int32_t y); +    void ToggleFlag(int32_t x, int32_t y); -    private: -        void Reinit(); -        void InitIsMineBitmap(int32_t mine_count); -        void InitAdjacentMineCounters(); +    bool IsCovered(int32_t x, int32_t y); +    bool IsFlagged(int32_t x, int32_t y); +    bool IsMine(int32_t x, int32_t y); -        void Uncover(int32_t x, int32_t y); -        void ToggleFlag(int32_t x, int32_t y); -        bool IsCovered(int32_t x, int32_t y); -        bool IsFlagged(int32_t x, int32_t y); -        bool IsMine(int32_t x, int32_t y); +    V2F32 ScreenPosToViewPos(V2F32 screen_pos, RenderGroup& render_group); -        V2F32 ScreenPosToViewPos(V2F32 screen_pos, RenderGroup &render_group); +private: +    void DrawBoard(); +    void DrawStartMenu(); +    void DrawPauseMenu(); +    void DrawGameOverMenu(); -    private: -        void DrawPauseMenu(RenderGroup &render_group); -        void DrawGameOverMenu(RenderGroup &render_group); -        void DrawBoard(RenderGroup &render_group); +private: +    static constexpr int32_t MAX_MAP_HEIGHT = 32; +    static constexpr int32_t MAX_MAP_WIDTH = 32; +    static constexpr std::string_view s_FontFilepath = "./fonts/dejavu_ttf/DejaVuSans.ttf"; -    private: -        static constexpr int32_t MAX_MAP_HEIGHT = 32; -        static constexpr int32_t MAX_MAP_WIDTH = 32; -        static constexpr std::string_view s_FontFilepath = "./fonts/dejavu_ttf/DejaVuSans.ttf"; +private: +    RenderGroup& m_render_group; -    private: -        MinesweeperRunState m_RunState = MinesweeperRunState::Resume; +    RunState m_run_state = start_menu; +    Difficulty m_difficulty = beginner; -        float m_WorldWidth = 4.0f; -        float m_WorldHeight = 3.0f; +    float m_world_width = 4.0f; +    float m_world_height = 3.0f; -        int32_t m_MapWidth = 16; -        int32_t m_MapHeight = 16; +    int32_t m_grid_width; +    int32_t m_grid_height; -        V2F32 m_MapViewPos; -        V2F32 m_CellOuterViewSize; -        V2F32 m_CellInnerViewSize; +    V2F32 m_grid_pos; +    V2F32 m_cell_outer_size; +    V2F32 m_cell_inner_size; -        uint32_t m_IsCoveredBitmap[MAX_MAP_HEIGHT] {}; -        uint32_t m_IsFlaggedBitmap[MAX_MAP_HEIGHT] {}; -        uint32_t m_IsMineBitmap[MAX_MAP_HEIGHT] {}; -        int32_t m_AdjacentMineCounters[MAX_MAP_WIDTH * MAX_MAP_HEIGHT] {}; +    uint32_t m_is_covered_bitmap[MAX_MAP_HEIGHT] {}; +    uint32_t m_is_flagged_bitmap[MAX_MAP_HEIGHT] {}; +    uint32_t m_is_mine_bitmap[MAX_MAP_HEIGHT] {}; +    int32_t m_adjacent_mine_counts[MAX_MAP_WIDTH * MAX_MAP_HEIGHT] {}; -        Font m_Font; -        std::array<Glyph, 9> m_DigitGlyphs; +    Font m_font; +    std::array<Glyph, 9> m_digit_glyphs;  };  | 
