diff options
Diffstat (limited to 'Games')
-rw-r--r-- | Games/Minesweeper/Field.h | 2 | ||||
-rw-r--r-- | Games/Minesweeper/main.cpp | 12 | ||||
-rw-r--r-- | Games/Snake/SnakeGame.h | 3 | ||||
-rw-r--r-- | Games/Snake/main.cpp | 2 |
4 files changed, 10 insertions, 9 deletions
diff --git a/Games/Minesweeper/Field.h b/Games/Minesweeper/Field.h index e976d26189..fff4cb0161 100644 --- a/Games/Minesweeper/Field.h +++ b/Games/Minesweeper/Field.h @@ -32,9 +32,9 @@ public: }; class Field final : public GFrame { + C_OBJECT(Field) friend class Square; friend class SquareLabel; - public: Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed); virtual ~Field() override; diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp index 5299572f74..c7083785d8 100644 --- a/Games/Minesweeper/main.cpp +++ b/Games/Minesweeper/main.cpp @@ -39,7 +39,7 @@ int main(int argc, char** argv) auto time_icon_label = GLabel::construct(container); time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png")); auto time_label = GLabel::construct(container); - auto* field = new Field(*flag_label, *time_label, *face_button, widget, [&](Size size) { + auto field = Field::construct(*flag_label, *time_label, *face_button, widget, [&](Size size) { size.set_height(size.height() + container->preferred_size().height()); window->resize(size); }); @@ -48,7 +48,7 @@ int main(int argc, char** argv) auto app_menu = make<GMenu>("Minesweeper"); - app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [field](const GAction&) { + app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&](const GAction&) { field->reset(); })); @@ -74,16 +74,16 @@ int main(int argc, char** argv) menubar->add_menu(move(app_menu)); auto difficulty_menu = make<GMenu>("Difficulty"); - difficulty_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [field](const GAction&) { + difficulty_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [&](const GAction&) { field->set_field_size(9, 9, 10); })); - difficulty_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [field](const GAction&) { + difficulty_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [&](const GAction&) { field->set_field_size(16, 16, 40); })); - difficulty_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [field](const GAction&) { + difficulty_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [&](const GAction&) { field->set_field_size(16, 30, 99); })); - difficulty_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [field](const GAction&) { + difficulty_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [&](const GAction&) { field->set_field_size(32, 60, 350); })); menubar->add_menu(move(difficulty_menu)); diff --git a/Games/Snake/SnakeGame.h b/Games/Snake/SnakeGame.h index 2c03e2541b..ac002158ac 100644 --- a/Games/Snake/SnakeGame.h +++ b/Games/Snake/SnakeGame.h @@ -5,13 +5,14 @@ #include <LibGUI/GWidget.h> class SnakeGame : public GWidget { + C_OBJECT(SnakeGame) public: - explicit SnakeGame(GWidget* parent = nullptr); virtual ~SnakeGame() override; void reset(); private: + explicit SnakeGame(GWidget* parent = nullptr); virtual void paint_event(GPaintEvent&) override; virtual void keydown_event(GKeyEvent&) override; virtual void timer_event(CTimerEvent&) override; diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp index e8df14fd36..2000cc2aa4 100644 --- a/Games/Snake/main.cpp +++ b/Games/Snake/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char** argv) window->set_title("Snake"); window->set_rect(100, 100, 320, 320); - auto* game = new SnakeGame; + auto game = SnakeGame::construct(); window->set_main_widget(game); auto menubar = make<GMenuBar>(); |