diff options
author | Sam Atkins <github@samatkins.co.uk> | 2021-06-11 12:33:27 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-06-11 22:42:38 +0200 |
commit | adedb3de2a5f5b59dab17bfda6e7240e15352af8 (patch) | |
tree | 264b04b9b294dfa653d1a6030443487e75b53653 /Userland/Games | |
parent | 8d8b1d95319fd3ce878d6ec67cae27fc3fcc15e8 (diff) | |
download | serenity-adedb3de2a5f5b59dab17bfda6e7240e15352af8.zip |
Solitaire: Subtract points when undoing a card-flip
Solitaire: Correct default arg definition location
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/Solitaire/Game.cpp | 10 | ||||
-rw-r--r-- | Userland/Games/Solitaire/Game.h | 3 |
2 files changed, 10 insertions, 3 deletions
diff --git a/Userland/Games/Solitaire/Game.cpp b/Userland/Games/Solitaire/Game.cpp index 0b7a4c86e5..35a034bc12 100644 --- a/Userland/Games/Solitaire/Game.cpp +++ b/Userland/Games/Solitaire/Game.cpp @@ -139,7 +139,7 @@ void Game::start_timer_if_necessary() } } -void Game::score_move(CardStack& from, CardStack& to, bool inverse = false) +void Game::score_move(CardStack& from, CardStack& to, bool inverse) { if (from.type() == CardStack::Type::Play && to.type() == CardStack::Type::Normal) { update_score(5 * (inverse ? -1 : 1)); @@ -152,6 +152,11 @@ void Game::score_move(CardStack& from, CardStack& to, bool inverse = false) } } +void Game::score_flip(bool inverse) +{ + update_score(5 * (inverse ? -1 : 1)); +} + void Game::update_score(int to_add) { m_score = max(static_cast<int>(m_score) + to_add, 0); @@ -200,7 +205,7 @@ void Game::mousedown_event(GUI::MouseEvent& event) if (top_card.is_upside_down()) { if (top_card.rect().contains(click_location)) { top_card.set_upside_down(false); - update_score(5); + score_flip(); update(top_card.rect()); remember_flip_for_undo(top_card); } @@ -600,6 +605,7 @@ void Game::perform_undo() if (on_undo_availability_change) on_undo_availability_change(false); invalidate_layout(); + score_flip(true); return; } diff --git a/Userland/Games/Solitaire/Game.h b/Userland/Games/Solitaire/Game.h index 30168bd13c..a49199f295 100644 --- a/Userland/Games/Solitaire/Game.h +++ b/Userland/Games/Solitaire/Game.h @@ -155,7 +155,8 @@ private: } void mark_intersecting_stacks_dirty(Card& intersecting_card); - void score_move(CardStack& from, CardStack& to, bool inverse); + void score_move(CardStack& from, CardStack& to, bool inverse = false); + void score_flip(bool inverse = false); void remember_move_for_undo(CardStack& from, CardStack& to, NonnullRefPtrVector<Card> moved_cards); void remember_flip_for_undo(Card& card); void update_score(int to_add); |