mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
Spider: Make Game creation fallible
This commit is contained in:
parent
f9f6bf3cd4
commit
e193679352
3 changed files with 13 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue