mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:37:35 +00:00
Minesweeper: Start working on a simple minesweeper game. :^)
This commit is contained in:
parent
c06a3bdeb4
commit
a90e218c71
17 changed files with 288 additions and 1 deletions
53
Games/Minesweeper/Field.h
Normal file
53
Games/Minesweeper/Field.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibGUI/GWidget.h>
|
||||
|
||||
class SquareButton;
|
||||
class GLabel;
|
||||
|
||||
struct Square {
|
||||
bool is_swept { false };
|
||||
bool has_mine { false };
|
||||
bool has_flag { false };
|
||||
int row { 0 };
|
||||
int column { 0 };
|
||||
int number { 0 };
|
||||
SquareButton* button { nullptr };
|
||||
GLabel* label { nullptr };
|
||||
};
|
||||
|
||||
class Field final : public GWidget {
|
||||
public:
|
||||
explicit Field(GWidget* parent);
|
||||
virtual ~Field() override;
|
||||
|
||||
int rows() const { return m_rows; }
|
||||
int columns() const { return m_columns; }
|
||||
int mine_count() const { return m_mine_count; }
|
||||
int square_size() const { return 15; }
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
void on_square_clicked(Square&);
|
||||
void on_square_right_clicked(Square&);
|
||||
void game_over();
|
||||
|
||||
Square& square(int row, int column) { return m_squares[row * columns() + column]; }
|
||||
const Square& square(int row, int column) const { return m_squares[row * columns() + column]; }
|
||||
|
||||
void flood_fill(Square&);
|
||||
|
||||
template<typename Callback> void for_each_neighbor_of(const Square&, Callback);
|
||||
|
||||
int m_rows { 10 };
|
||||
int m_columns { 10 };
|
||||
int m_mine_count { 10 };
|
||||
Vector<Square> m_squares;
|
||||
RetainPtr<GraphicsBitmap> m_mine_bitmap;
|
||||
RetainPtr<GraphicsBitmap> m_flag_bitmap;
|
||||
RetainPtr<GraphicsBitmap> m_one_bitmap;
|
||||
RetainPtr<GraphicsBitmap> m_two_bitmap;
|
||||
RetainPtr<GraphicsBitmap> m_three_bitmap;
|
||||
RetainPtr<GraphicsBitmap> m_four_bitmap;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue