mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:17:35 +00:00
Solitaire: Make double-click skip the new-game animation
This commit is contained in:
parent
e8d83b1ae1
commit
5de8b38783
2 changed files with 35 additions and 24 deletions
|
@ -48,27 +48,10 @@ static float rand_float()
|
||||||
return get_random_uniform(RAND_MAX) / static_cast<float>(RAND_MAX);
|
return get_random_uniform(RAND_MAX) / static_cast<float>(RAND_MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::timer_event(Core::TimerEvent&)
|
void Game::deal_next_card()
|
||||||
{
|
{
|
||||||
switch (m_state) {
|
VERIFY(m_state == State::NewGameAnimation);
|
||||||
case State::StartGameOverAnimationNextFrame: {
|
|
||||||
m_state = State::GameOverAnimation;
|
|
||||||
set_background_fill_enabled(false);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case State::GameOverAnimation: {
|
|
||||||
if (m_animation.position().x() >= Game::width || m_animation.card_rect().right() <= 0)
|
|
||||||
create_new_animation_card();
|
|
||||||
|
|
||||||
if (m_animation.tick())
|
|
||||||
update(m_animation.card_rect());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case State::NewGameAnimation: {
|
|
||||||
if (m_new_game_animation_delay < new_game_animation_delay) {
|
|
||||||
++m_new_game_animation_delay;
|
|
||||||
} else {
|
|
||||||
m_new_game_animation_delay = 0;
|
|
||||||
auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile));
|
auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile));
|
||||||
|
|
||||||
if (current_pile.count() < m_new_game_animation_pile) {
|
if (current_pile.count() < m_new_game_animation_pile) {
|
||||||
|
@ -93,6 +76,30 @@ void Game::timer_event(Core::TimerEvent&)
|
||||||
stop_timer();
|
stop_timer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Game::timer_event(Core::TimerEvent&)
|
||||||
|
{
|
||||||
|
switch (m_state) {
|
||||||
|
case State::StartGameOverAnimationNextFrame: {
|
||||||
|
m_state = State::GameOverAnimation;
|
||||||
|
set_background_fill_enabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State::GameOverAnimation: {
|
||||||
|
if (m_animation.position().x() >= Game::width || m_animation.card_rect().right() <= 0)
|
||||||
|
create_new_animation_card();
|
||||||
|
|
||||||
|
if (m_animation.tick())
|
||||||
|
update(m_animation.card_rect());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case State::NewGameAnimation: {
|
||||||
|
if (m_new_game_animation_delay < new_game_animation_delay) {
|
||||||
|
++m_new_game_animation_delay;
|
||||||
|
} else {
|
||||||
|
m_new_game_animation_delay = 0;
|
||||||
|
deal_next_card();
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -365,8 +372,11 @@ void Game::doubleclick_event(GUI::MouseEvent& event)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_state == State::NewGameAnimation)
|
if (m_state == State::NewGameAnimation) {
|
||||||
|
while (m_state == State::NewGameAnimation)
|
||||||
|
deal_next_card();
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
auto click_location = event.position();
|
auto click_location = event.position();
|
||||||
for (auto& to_check : stacks()) {
|
for (auto& to_check : stacks()) {
|
||||||
|
|
|
@ -187,6 +187,7 @@ private:
|
||||||
void set_background_fill_enabled(bool);
|
void set_background_fill_enabled(bool);
|
||||||
void check_for_game_over();
|
void check_for_game_over();
|
||||||
void clear_hovered_stack();
|
void clear_hovered_stack();
|
||||||
|
void deal_next_card();
|
||||||
|
|
||||||
virtual void paint_event(GUI::PaintEvent&) override;
|
virtual void paint_event(GUI::PaintEvent&) override;
|
||||||
virtual void mousedown_event(GUI::MouseEvent&) override;
|
virtual void mousedown_event(GUI::MouseEvent&) override;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue