mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:57:35 +00:00
Solitaire: Add undo functionality
This commit is contained in:
parent
9444272ba0
commit
ab4f4ddc3c
3 changed files with 125 additions and 10 deletions
|
@ -37,10 +37,12 @@ public:
|
|||
|
||||
Mode mode() const { return m_mode; }
|
||||
void setup(Mode);
|
||||
void perform_undo();
|
||||
|
||||
Function<void(uint32_t)> on_score_update;
|
||||
Function<void()> on_game_start;
|
||||
Function<void(GameOverReason, uint32_t)> on_game_end;
|
||||
Function<void(bool)> on_undo_availability_change;
|
||||
|
||||
private:
|
||||
Game();
|
||||
|
@ -103,6 +105,19 @@ private:
|
|||
int8_t punishment { 0 };
|
||||
};
|
||||
|
||||
struct LastMove {
|
||||
enum class Type {
|
||||
Invalid,
|
||||
MoveCards,
|
||||
FlipCard
|
||||
};
|
||||
|
||||
Type type { Type::Invalid };
|
||||
CardStack* from { nullptr };
|
||||
NonnullRefPtrVector<Card> cards;
|
||||
CardStack* to { nullptr };
|
||||
};
|
||||
|
||||
enum StackLocation {
|
||||
Stock,
|
||||
Waste,
|
||||
|
@ -140,6 +155,9 @@ private:
|
|||
}
|
||||
|
||||
void mark_intersecting_stacks_dirty(Card& intersecting_card);
|
||||
void score_move(CardStack& from, CardStack& to, bool inverse);
|
||||
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);
|
||||
void move_card(CardStack& from, CardStack& to);
|
||||
void start_game_over_animation();
|
||||
|
@ -163,6 +181,7 @@ private:
|
|||
|
||||
Mode m_mode { Mode::SingleCardDraw };
|
||||
|
||||
LastMove m_last_move;
|
||||
NonnullRefPtrVector<Card> m_focused_cards;
|
||||
NonnullRefPtrVector<Card> m_new_deck;
|
||||
CardStack m_stacks[StackLocation::__Count];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue