1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 13:47:35 +00:00

2048: Let user decide if he wants to continue the game

Before game finish when a player has reached target tile,
Now player will be able to decide if he wants to continue or not
This commit is contained in:
Mohsan Ali 2021-10-04 22:57:13 +05:00 committed by Ali Mohammad Pur
parent accf4b338d
commit d609dde7b0
3 changed files with 18 additions and 8 deletions

View file

@ -151,14 +151,23 @@ int main(int argc, char** argv)
case Game::MoveOutcome::InvalidMove:
undo_stack.take_last();
break;
case Game::MoveOutcome::Won:
case Game::MoveOutcome::Won: {
update();
GUI::MessageBox::show(window,
String::formatted("You reached {} in {} turns with a score of {}", game.target_tile(), game.turns(), game.score()),
"You won!",
GUI::MessageBox::Type::Information);
start_a_new_game();
auto message_box = GUI::MessageBox::construct(window, "Congratulations! You won the game, Do you still want to continue?",
"Want to continue?",
GUI::MessageBox::Type::Question,
GUI::MessageBox::InputType::YesNo);
if (message_box->exec() == GUI::MessageBox::ExecYes)
game.set_want_to_continue();
else {
GUI::MessageBox::show(window,
String::formatted("You reached {} in {} turns with a score of {}", game.largest_tile(), game.turns(), game.score()),
"You won!",
GUI::MessageBox::Type::Information);
start_a_new_game();
}
break;
}
case Game::MoveOutcome::GameOver:
update();
GUI::MessageBox::show(window,