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

2048: Added Redo Support

This commit is contained in:
Umar Haroon 2021-05-11 01:24:09 -06:00 committed by Linus Groh
parent a527256356
commit 53e1ee2cb7

View file

@ -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();