mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:07:34 +00:00
FlappyBug: Propagate errors in Bug class
Move-construct Bug into the Game class to improve error handling.
This commit is contained in:
parent
a67afa735c
commit
ff359c27e3
3 changed files with 21 additions and 5 deletions
|
@ -44,11 +44,26 @@ public:
|
|||
const float x { 50 };
|
||||
const float radius { 16 };
|
||||
const float starting_y { 200 };
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png").release_value_but_fixme_should_propagate_errors() };
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap { Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png").release_value_but_fixme_should_propagate_errors() };
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap;
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap;
|
||||
float y {};
|
||||
float velocity {};
|
||||
|
||||
private:
|
||||
Bug(NonnullRefPtr<Gfx::Bitmap> falling_bitmap_value, NonnullRefPtr<Gfx::Bitmap> flapping_bitmap_value)
|
||||
: falling_bitmap(move(falling_bitmap_value))
|
||||
, flapping_bitmap(move(flapping_bitmap_value))
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
static ErrorOr<Bug> construct()
|
||||
{
|
||||
NonnullRefPtr<Gfx::Bitmap> falling_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/falling.png"));
|
||||
NonnullRefPtr<Gfx::Bitmap> flapping_bitmap = TRY(Gfx::Bitmap::try_load_from_file("/res/icons/flappybug/flapping.png"));
|
||||
return Bug(move(falling_bitmap), move(flapping_bitmap));
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
y = starting_y;
|
||||
|
@ -153,7 +168,7 @@ private:
|
|||
const Gfx::IntRect m_score_rect { 10, 10, 20, 20 };
|
||||
const Gfx::IntRect m_text_rect { game_width / 2 - 80, game_height / 2 - 40, 160, 80 };
|
||||
|
||||
Game();
|
||||
Game(Bug);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue