1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 07:47:37 +00:00

Solitaire: Subtract points when undoing a card-flip

Solitaire: Correct default arg definition location
This commit is contained in:
Sam Atkins 2021-06-11 12:33:27 +01:00 committed by Andreas Kling
parent 8d8b1d9531
commit adedb3de2a
2 changed files with 10 additions and 3 deletions

View file

@ -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) { if (from.type() == CardStack::Type::Play && to.type() == CardStack::Type::Normal) {
update_score(5 * (inverse ? -1 : 1)); 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) void Game::update_score(int to_add)
{ {
m_score = max(static_cast<int>(m_score) + to_add, 0); 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.is_upside_down()) {
if (top_card.rect().contains(click_location)) { if (top_card.rect().contains(click_location)) {
top_card.set_upside_down(false); top_card.set_upside_down(false);
update_score(5); score_flip();
update(top_card.rect()); update(top_card.rect());
remember_flip_for_undo(top_card); remember_flip_for_undo(top_card);
} }
@ -600,6 +605,7 @@ void Game::perform_undo()
if (on_undo_availability_change) if (on_undo_availability_change)
on_undo_availability_change(false); on_undo_availability_change(false);
invalidate_layout(); invalidate_layout();
score_flip(true);
return; return;
} }

View file

@ -155,7 +155,8 @@ private:
} }
void mark_intersecting_stacks_dirty(Card& intersecting_card); 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_move_for_undo(CardStack& from, CardStack& to, NonnullRefPtrVector<Card> moved_cards);
void remember_flip_for_undo(Card& card); void remember_flip_for_undo(Card& card);
void update_score(int to_add); void update_score(int to_add);