mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 02:55:49 +03:00
Solitaire: Only start timer when a move happens
Previously, the timer started if you clicked within the game area, whether that was on a card or not. Now, we only start when you click on a card or otherwise attempt a move. As a bonus, we now immediately update the status bar time indicator on game start, instead of having to wait until 1 second has elapsed.
This commit is contained in:
parent
8ee447b718
commit
679f831451
Notes:
sideshowbarker
2024-07-18 12:18:06 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/679f831451b Pull-request: https://github.com/SerenityOS/serenity/pull/8027 Issue: https://github.com/SerenityOS/serenity/issues/7792 Reviewed-by: https://github.com/linusg
@ -201,8 +201,6 @@ void Game::mousedown_event(GUI::MouseEvent& event)
|
||||
if (m_new_game_animation || m_game_over_animation)
|
||||
return;
|
||||
|
||||
start_timer_if_necessary();
|
||||
|
||||
auto click_location = event.position();
|
||||
for (auto& to_check : m_stacks) {
|
||||
if (to_check.type() == CardStack::Type::Waste)
|
||||
@ -218,6 +216,7 @@ void Game::mousedown_event(GUI::MouseEvent& event)
|
||||
if (top_card.rect().contains(click_location)) {
|
||||
top_card.set_upside_down(false);
|
||||
score_flip();
|
||||
start_timer_if_necessary();
|
||||
update(top_card.rect());
|
||||
remember_flip_for_undo(top_card);
|
||||
}
|
||||
@ -227,6 +226,7 @@ void Game::mousedown_event(GUI::MouseEvent& event)
|
||||
to_check.set_focused(true);
|
||||
m_focused_stack = &to_check;
|
||||
m_mouse_down = true;
|
||||
start_timer_if_necessary();
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -410,6 +410,8 @@ void Game::draw_cards()
|
||||
else
|
||||
update(play_bounding_box);
|
||||
}
|
||||
|
||||
start_timer_if_necessary();
|
||||
}
|
||||
|
||||
void Game::pop_waste_to_play_stack()
|
||||
@ -462,6 +464,7 @@ bool Game::attempt_to_move_card_to_foundations(CardStack& from)
|
||||
if (from.type() == CardStack::Type::Play)
|
||||
pop_waste_to_play_stack();
|
||||
|
||||
start_timer_if_necessary();
|
||||
check_for_game_over();
|
||||
}
|
||||
|
||||
@ -481,10 +484,8 @@ void Game::auto_move_eligible_cards_to_foundations()
|
||||
}
|
||||
|
||||
// If at least one card was moved, check again to see if now any additional cards can now be moved
|
||||
if (card_was_moved) {
|
||||
start_timer_if_necessary();
|
||||
if (card_was_moved)
|
||||
auto_move_eligible_cards_to_foundations();
|
||||
}
|
||||
}
|
||||
|
||||
void Game::mark_intersecting_stacks_dirty(Card& intersecting_card)
|
||||
|
@ -129,6 +129,7 @@ int main(int argc, char** argv)
|
||||
game.on_game_start = [&]() {
|
||||
seconds_elapsed = 0;
|
||||
timer->start();
|
||||
statusbar.set_text(2, "Time: 00:00:00");
|
||||
};
|
||||
game.on_game_end = [&](Solitaire::GameOverReason reason, uint32_t score) {
|
||||
if (timer->is_active())
|
||||
|
Loading…
Reference in New Issue
Block a user