mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 23:48:11 +00:00
53 lines
1.4 KiB
C++
53 lines
1.4 KiB
C++
#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;
|
|
};
|