diff options
author | Umar Haroon <umar.m.haroon@gmail.com> | 2021-05-11 01:24:09 -0600 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-05-11 10:22:27 +0100 |
commit | 53e1ee2cb77b365687637a55b0d2e6b5422e82e5 (patch) | |
tree | 161ee81c5012d7d5d1f5a11433e5a9a5f89caccc /Userland/Games | |
parent | a5272563567346ef1085d55c63934f41360d6784 (diff) | |
download | serenity-53e1ee2cb77b365687637a55b0d2e6b5422e82e5.zip |
2048: Added Redo Support
Diffstat (limited to 'Userland/Games')
-rw-r--r-- | Userland/Games/2048/main.cpp | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/Userland/Games/2048/main.cpp b/Userland/Games/2048/main.cpp index 4c12afe699..50bd678454 100644 --- a/Userland/Games/2048/main.cpp +++ b/Userland/Games/2048/main.cpp @@ -89,6 +89,7 @@ int main(int argc, char** argv) update(); Vector<Game> undo_stack; + Vector<Game> redo_stack; auto change_settings = [&] { auto size_dialog = GameSizeDialog::construct(window); @@ -116,6 +117,7 @@ int main(int argc, char** argv) auto start_a_new_game = [&] { // Do not leak game states between games. undo_stack.clear(); + redo_stack.clear(); game = Game(board_size, target_tile); @@ -169,9 +171,17 @@ int main(int argc, char** argv) game_menu.add_action(GUI::CommonActions::make_undo_action([&](auto&) { if (undo_stack.is_empty()) return; + redo_stack.append(game); game = undo_stack.take_last(); update(); })); + game_menu.add_action(GUI::CommonActions::make_redo_action([&](auto&) { + if (redo_stack.is_empty()) + return; + undo_stack.append(game); + game = redo_stack.take_last(); + update(); + })); game_menu.add_separator(); |