mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 09:30:24 +00:00
2048: Refactor tile sliding and score logic out of attempt_move()
This commit is contained in:
parent
24c5b0e81c
commit
3e8220dec2
Notes:
sideshowbarker
2024-07-18 17:52:43 +09:00
Author: https://github.com/dmitrii-ubskii 🔰 Commit: https://github.com/SerenityOS/serenity/commit/3e8220dec26 Pull-request: https://github.com/SerenityOS/serenity/pull/7146 Reviewed-by: https://github.com/bugaevc ✅ Reviewed-by: https://github.com/linusg
2 changed files with 13 additions and 2 deletions
|
@ -161,7 +161,7 @@ static bool is_stalled(const Game::Board& board)
|
|||
return true;
|
||||
}
|
||||
|
||||
Game::MoveOutcome Game::attempt_move(Direction direction)
|
||||
bool Game::slide_tiles(Direction direction)
|
||||
{
|
||||
size_t successful_merge_score = 0;
|
||||
Board new_board;
|
||||
|
@ -184,9 +184,18 @@ Game::MoveOutcome Game::attempt_move(Direction direction)
|
|||
bool moved = new_board != m_board;
|
||||
if (moved) {
|
||||
m_board = new_board;
|
||||
m_score += successful_merge_score;
|
||||
}
|
||||
|
||||
return moved;
|
||||
}
|
||||
|
||||
Game::MoveOutcome Game::attempt_move(Direction direction)
|
||||
{
|
||||
bool moved = slide_tiles(direction);
|
||||
if (moved) {
|
||||
m_turns++;
|
||||
add_random_tile();
|
||||
m_score += successful_merge_score;
|
||||
}
|
||||
|
||||
if (is_complete(m_board, m_target_tile))
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
bool slide_tiles(Direction);
|
||||
|
||||
void add_random_tile();
|
||||
|
||||
size_t m_grid_size { 0 };
|
||||
|
|
Loading…
Reference in a new issue