Minesweeper: Paint a grid pattern below the mines.

This commit is contained in:
Andreas Kling 2019-04-15 02:45:04 +02:00
parent bc5148354f
commit 791e8f5bb0
2 changed files with 24 additions and 1 deletions

View file

@ -1,8 +1,9 @@
#include "Field.h" #include "Field.h"
#include <LibGUI/GButton.h> #include <LibGUI/GButton.h>
#include <LibGUI/GLabel.h> #include <LibGUI/GLabel.h>
#include <AK/HashTable.h> #include <LibGUI/GPainter.h>
#include <LibCore/CConfigFile.h> #include <LibCore/CConfigFile.h>
#include <AK/HashTable.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #include <time.h>
@ -180,6 +181,26 @@ void Field::flood_fill(Square& square)
}); });
} }
void Field::paint_event(GPaintEvent& event)
{
GFrame::paint_event(event);
GPainter painter(*this);
painter.add_clip_rect(event.rect());
auto inner_rect = frame_inner_rect();
for (int y = inner_rect.top() - 1; y <= inner_rect.bottom(); y += square_size()) {
Point a { inner_rect.left(), y };
Point b { inner_rect.right(), y };
painter.draw_line(a, b, Color::MidGray);
}
for (int x = frame_inner_rect().left() - 1; x <= frame_inner_rect().right(); x += square_size()) {
Point a { x, inner_rect.top() };
Point b { x, inner_rect.bottom() };
painter.draw_line(a, b, Color::MidGray);
}
}
void Field::on_square_clicked(Square& square) void Field::on_square_clicked(Square& square)
{ {
if (square.is_swept) if (square.is_swept)

View file

@ -31,6 +31,8 @@ public:
void reset(); void reset();
private: private:
virtual void paint_event(GPaintEvent&) override;
void on_square_clicked(Square&); void on_square_clicked(Square&);
void on_square_right_clicked(Square&); void on_square_right_clicked(Square&);
void game_over(); void game_over();