mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 00:47:45 +00:00
2048: Move out the 'undo' action to the app menu/action
This commit is contained in:
parent
d97025567a
commit
2336c62901
3 changed files with 13 additions and 8 deletions
|
@ -235,14 +235,6 @@ void TwentyFortyEightGame::keydown_event(GUI::KeyEvent& event)
|
||||||
case KeyCode::Key_Down:
|
case KeyCode::Key_Down:
|
||||||
new_state.board = reverse(slide_left(reverse(previous_state.board), successful_merge_score));
|
new_state.board = reverse(slide_left(reverse(previous_state.board), successful_merge_score));
|
||||||
break;
|
break;
|
||||||
case KeyCode::Key_U:
|
|
||||||
case KeyCode::Key_Backspace:
|
|
||||||
if (m_states.size() > 1) {
|
|
||||||
m_states.take_last();
|
|
||||||
update();
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -349,3 +341,12 @@ int TwentyFortyEightGame::score() const
|
||||||
{
|
{
|
||||||
return m_states.last().score;
|
return m_states.last().score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TwentyFortyEightGame::undo()
|
||||||
|
{
|
||||||
|
if (m_states.size() > 1) {
|
||||||
|
m_states.take_last();
|
||||||
|
--m_current_turn;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ public:
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
int score() const;
|
int score() const;
|
||||||
|
void undo();
|
||||||
|
|
||||||
struct State {
|
struct State {
|
||||||
Vector<Vector<u32>> board;
|
Vector<Vector<u32>> board;
|
||||||
|
|
|
@ -75,6 +75,9 @@ int main(int argc, char** argv)
|
||||||
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
|
app_menu.add_action(GUI::Action::create("New game", { Mod_None, Key_F2 }, [&](auto&) {
|
||||||
game.reset();
|
game.reset();
|
||||||
}));
|
}));
|
||||||
|
app_menu.add_action(GUI::CommonActions::make_undo_action([&](auto&) {
|
||||||
|
game.undo();
|
||||||
|
}));
|
||||||
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
app_menu.add_action(GUI::CommonActions::make_quit_action([](auto&) {
|
||||||
GUI::Application::the()->quit();
|
GUI::Application::the()->quit();
|
||||||
}));
|
}));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue