mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-04 01:05:58 +03:00
Spider: Make Game creation fallible
This commit is contained in:
parent
f9f6bf3cd4
commit
e193679352
Notes:
sideshowbarker
2024-07-17 05:03:11 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/e193679352 Pull-request: https://github.com/SerenityOS/serenity/pull/16851 Reviewed-by: https://github.com/linusg Reviewed-by: https://github.com/trflynn89 ✅
@ -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<NonnullRefPtr<Game>> 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)
|
||||
|
@ -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<NonnullRefPtr<Game>> try_create();
|
||||
~Game() override = default;
|
||||
|
||||
Mode mode() const { return m_mode; }
|
||||
|
@ -118,7 +118,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
update_statistic_display(StatisticDisplay::HighScore);
|
||||
|
||||
auto widget = TRY(window->try_set_main_widget<GUI::Widget>());
|
||||
widget->load_from_gml(spider_gml);
|
||||
TRY(widget->try_load_from_gml(spider_gml));
|
||||
|
||||
auto& game = *widget->find_descendant_of_type_named<Spider::Game>("game");
|
||||
game.set_focus(true);
|
||||
|
Loading…
Reference in New Issue
Block a user