diff --git a/Userland/Games/Spider/Game.cpp b/Userland/Games/Spider/Game.cpp index 3f0caf23d3a..6473b31c7bc 100644 --- a/Userland/Games/Spider/Game.cpp +++ b/Userland/Games/Spider/Game.cpp @@ -20,16 +20,22 @@ static constexpr uint8_t new_game_animation_delay = 2; static constexpr uint8_t draw_animation_delay = 2; static constexpr int s_timer_interval_ms = 1000 / 60; -Game::Game() +ErrorOr> Game::try_create() { - MUST(add_stack(Gfx::IntPoint { 10, Game::height - Card::height - 10 }, CardStack::Type::Waste)); - MUST(add_stack(Gfx::IntPoint { Game::width - Card::width - 10, Game::height - Card::height - 10 }, CardStack::Type::Stock)); + auto game = TRY(adopt_nonnull_ref_or_enomem(new (nothrow) Game())); + + TRY(game->add_stack(Gfx::IntPoint { 10, Game::height - Card::height - 10 }, CardStack::Type::Waste)); + TRY(game->add_stack(Gfx::IntPoint { Game::width - Card::width - 10, Game::height - Card::height - 10 }, CardStack::Type::Stock)); for (int i = 0; i < 10; i++) { - MUST(add_stack(Gfx::IntPoint { 10 + i * (Card::width + 10), 10 }, CardStack::Type::Normal)); + TRY(game->add_stack(Gfx::IntPoint { 10 + i * (Card::width + 10), 10 }, CardStack::Type::Normal)); } + + return game; } +Game::Game() = default; + void Game::setup(Mode mode) { if (m_new_game_animation) diff --git a/Userland/Games/Spider/Game.h b/Userland/Games/Spider/Game.h index 1df7b50915a..b89c2d508ed 100644 --- a/Userland/Games/Spider/Game.h +++ b/Userland/Games/Spider/Game.h @@ -30,11 +30,12 @@ enum class GameOverReason { }; class Game final : public Cards::CardGame { - C_OBJECT(Game) + C_OBJECT_ABSTRACT(Game) public: static constexpr int width = 10 + 10 * Card::width + 90 + 10; static constexpr int height = 480; + static ErrorOr> try_create(); ~Game() override = default; Mode mode() const { return m_mode; } diff --git a/Userland/Games/Spider/main.cpp b/Userland/Games/Spider/main.cpp index 40bce72dc9d..6bd101e05c4 100644 --- a/Userland/Games/Spider/main.cpp +++ b/Userland/Games/Spider/main.cpp @@ -118,7 +118,7 @@ ErrorOr serenity_main(Main::Arguments arguments) update_statistic_display(StatisticDisplay::HighScore); auto widget = TRY(window->try_set_main_widget()); - widget->load_from_gml(spider_gml); + TRY(widget->try_load_from_gml(spider_gml)); auto& game = *widget->find_descendant_of_type_named("game"); game.set_focus(true);