mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:07:36 +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,6 +48,35 @@ 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::deal_next_card()
|
||||||
|
{
|
||||||
|
VERIFY(m_state == State::NewGameAnimation);
|
||||||
|
|
||||||
|
auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile));
|
||||||
|
|
||||||
|
if (current_pile.count() < m_new_game_animation_pile) {
|
||||||
|
auto card = m_new_deck.take_last();
|
||||||
|
card->set_upside_down(true);
|
||||||
|
current_pile.push(card).release_value_but_fixme_should_propagate_errors();
|
||||||
|
} else {
|
||||||
|
current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
++m_new_game_animation_pile;
|
||||||
|
}
|
||||||
|
|
||||||
|
update(current_pile.bounding_box());
|
||||||
|
|
||||||
|
if (m_new_game_animation_pile == piles.size()) {
|
||||||
|
auto& stock_pile = stack_at_location(Stock);
|
||||||
|
while (!m_new_deck.is_empty())
|
||||||
|
stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors();
|
||||||
|
|
||||||
|
update(stock_pile.bounding_box());
|
||||||
|
|
||||||
|
m_state = State::WaitingForNewGame;
|
||||||
|
stop_timer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Game::timer_event(Core::TimerEvent&)
|
void Game::timer_event(Core::TimerEvent&)
|
||||||
{
|
{
|
||||||
switch (m_state) {
|
switch (m_state) {
|
||||||
|
@ -69,29 +98,7 @@ void Game::timer_event(Core::TimerEvent&)
|
||||||
++m_new_game_animation_delay;
|
++m_new_game_animation_delay;
|
||||||
} else {
|
} else {
|
||||||
m_new_game_animation_delay = 0;
|
m_new_game_animation_delay = 0;
|
||||||
auto& current_pile = stack_at_location(piles.at(m_new_game_animation_pile));
|
deal_next_card();
|
||||||
|
|
||||||
if (current_pile.count() < m_new_game_animation_pile) {
|
|
||||||
auto card = m_new_deck.take_last();
|
|
||||||
card->set_upside_down(true);
|
|
||||||
current_pile.push(card).release_value_but_fixme_should_propagate_errors();
|
|
||||||
} else {
|
|
||||||
current_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors();
|
|
||||||
++m_new_game_animation_pile;
|
|
||||||
}
|
|
||||||
|
|
||||||
update(current_pile.bounding_box());
|
|
||||||
|
|
||||||
if (m_new_game_animation_pile == piles.size()) {
|
|
||||||
auto& stock_pile = stack_at_location(Stock);
|
|
||||||
while (!m_new_deck.is_empty())
|
|
||||||
stock_pile.push(m_new_deck.take_last()).release_value_but_fixme_should_propagate_errors();
|
|
||||||
|
|
||||||
update(stock_pile.bounding_box());
|
|
||||||
|
|
||||||
m_state = State::WaitingForNewGame;
|
|
||||||
stop_timer();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -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