mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +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:
parent
accf4b338d
commit
d609dde7b0
3 changed files with 18 additions and 8 deletions
|
@ -232,7 +232,7 @@ Game::MoveOutcome Game::attempt_move(Direction direction)
|
|||
add_tile();
|
||||
}
|
||||
|
||||
if (is_complete(m_board, m_target_tile))
|
||||
if (is_complete(m_board, m_target_tile) && !m_want_to_continue)
|
||||
return MoveOutcome::Won;
|
||||
if (m_board.is_stalled())
|
||||
return MoveOutcome::GameOver;
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
size_t turns() const { return m_turns; }
|
||||
u32 target_tile() const { return m_target_tile; }
|
||||
u32 largest_tile() const;
|
||||
|
||||
void set_want_to_continue() { m_want_to_continue = true; }
|
||||
class Board {
|
||||
public:
|
||||
using Row = Vector<u32>;
|
||||
|
@ -119,6 +119,7 @@ private:
|
|||
u32 m_target_tile { 0 };
|
||||
|
||||
bool m_evil_ai { false };
|
||||
bool m_want_to_continue { false };
|
||||
|
||||
Board m_board;
|
||||
size_t m_score { 0 };
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue