diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 02:45:04 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-15 02:45:04 +0200 |
commit | 791e8f5bb05bc6a251ced627012857fa8e4ac855 (patch) | |
tree | 1453b6ac3f5c727d563609fbfe7c92ca34766429 | |
parent | bc5148354f6ad777ed9ba2988bd0547b16956102 (diff) | |
download | serenity-791e8f5bb05bc6a251ced627012857fa8e4ac855.zip |
Minesweeper: Paint a grid pattern below the mines.
-rw-r--r-- | Games/Minesweeper/Field.cpp | 23 | ||||
-rw-r--r-- | Games/Minesweeper/Field.h | 2 |
2 files changed, 24 insertions, 1 deletions
diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp index 1480a445f8..fc6aceb543 100644 --- a/Games/Minesweeper/Field.cpp +++ b/Games/Minesweeper/Field.cpp @@ -1,8 +1,9 @@ #include "Field.h" #include <LibGUI/GButton.h> #include <LibGUI/GLabel.h> -#include <AK/HashTable.h> +#include <LibGUI/GPainter.h> #include <LibCore/CConfigFile.h> +#include <AK/HashTable.h> #include <unistd.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) { if (square.is_swept) diff --git a/Games/Minesweeper/Field.h b/Games/Minesweeper/Field.h index a8d57f9caa..2e91a24c37 100644 --- a/Games/Minesweeper/Field.h +++ b/Games/Minesweeper/Field.h @@ -31,6 +31,8 @@ public: void reset(); private: + virtual void paint_event(GPaintEvent&) override; + void on_square_clicked(Square&); void on_square_right_clicked(Square&); void game_over(); |