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

2048: Move out the 'undo' action to the app menu/action

This commit is contained in:
AnotherTest 2020-08-14 16:20:13 +04:30 committed by Andreas Kling
parent d97025567a
commit 2336c62901
3 changed files with 13 additions and 8 deletions

View file

@ -235,14 +235,6 @@ void TwentyFortyEightGame::keydown_event(GUI::KeyEvent& event)
case KeyCode::Key_Down:
new_state.board = reverse(slide_left(reverse(previous_state.board), successful_merge_score));
break;
case KeyCode::Key_U:
case KeyCode::Key_Backspace:
if (m_states.size() > 1) {
m_states.take_last();
update();
} else {
return;
}
default:
return;
}
@ -349,3 +341,12 @@ int TwentyFortyEightGame::score() const
{
return m_states.last().score;
}
void TwentyFortyEightGame::undo()
{
if (m_states.size() > 1) {
m_states.take_last();
--m_current_turn;
update();
}
}

View file

@ -36,6 +36,7 @@ public:
void reset();
int score() const;
void undo();
struct State {
Vector<Vector<u32>> board;

View file

@ -75,6 +75,9 @@ int main(int argc, char** argv)
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
game.reset();
}));
app_menu.add_action(GUI::CommonActions::make_undo_action([&](auto&) {
game.undo();
}));
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
GUI::Application::the()->quit();
}));