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();
|
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;
|
return MoveOutcome::Won;
|
||||||
if (m_board.is_stalled())
|
if (m_board.is_stalled())
|
||||||
return MoveOutcome::GameOver;
|
return MoveOutcome::GameOver;
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
size_t turns() const { return m_turns; }
|
size_t turns() const { return m_turns; }
|
||||||
u32 target_tile() const { return m_target_tile; }
|
u32 target_tile() const { return m_target_tile; }
|
||||||
u32 largest_tile() const;
|
u32 largest_tile() const;
|
||||||
|
void set_want_to_continue() { m_want_to_continue = true; }
|
||||||
class Board {
|
class Board {
|
||||||
public:
|
public:
|
||||||
using Row = Vector<u32>;
|
using Row = Vector<u32>;
|
||||||
|
@ -119,6 +119,7 @@ private:
|
||||||
u32 m_target_tile { 0 };
|
u32 m_target_tile { 0 };
|
||||||
|
|
||||||
bool m_evil_ai { false };
|
bool m_evil_ai { false };
|
||||||
|
bool m_want_to_continue { false };
|
||||||
|
|
||||||
Board m_board;
|
Board m_board;
|
||||||
size_t m_score { 0 };
|
size_t m_score { 0 };
|
||||||
|
|
|
@ -151,14 +151,23 @@ int main(int argc, char** argv)
|
||||||
case Game::MoveOutcome::InvalidMove:
|
case Game::MoveOutcome::InvalidMove:
|
||||||
undo_stack.take_last();
|
undo_stack.take_last();
|
||||||
break;
|
break;
|
||||||
case Game::MoveOutcome::Won:
|
case Game::MoveOutcome::Won: {
|
||||||
update();
|
update();
|
||||||
GUI::MessageBox::show(window,
|
auto message_box = GUI::MessageBox::construct(window, "Congratulations! You won the game, Do you still want to continue?",
|
||||||
String::formatted("You reached {} in {} turns with a score of {}", game.target_tile(), game.turns(), game.score()),
|
"Want to continue?",
|
||||||
"You won!",
|
GUI::MessageBox::Type::Question,
|
||||||
GUI::MessageBox::Type::Information);
|
GUI::MessageBox::InputType::YesNo);
|
||||||
start_a_new_game();
|
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;
|
break;
|
||||||
|
}
|
||||||
case Game::MoveOutcome::GameOver:
|
case Game::MoveOutcome::GameOver:
|
||||||
update();
|
update();
|
||||||
GUI::MessageBox::show(window,
|
GUI::MessageBox::show(window,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue