diff options
author | Dmitrii Ubskii <ubskydm@gmail.com> | 2021-06-12 02:46:11 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-12 00:46:11 +0100 |
commit | f11000b17655bccd832634e82aad1b040e3822a3 (patch) | |
tree | 27417cafffe5d97442da8fef64502ca059fe5d6c /Userland/Games/2048/Game.cpp | |
parent | a1f5357ad32584a10b9192ad148446ee14f24da2 (diff) | |
download | serenity-f11000b17655bccd832634e82aad1b040e3822a3.zip |
2048: Fix move success detection
Whether or not tiles moved used to be determined by comparing new_tiles
with m_tiles. This is no longer possible since the slide is done
in-place.
This fix makes the game look through the m_sliding_tiles, which contains
previous and current position for each tile on the board, to determine
whether any tile moved at all. If not, the move is deemed unsuccessful.
Fixes #8008.
Diffstat (limited to 'Userland/Games/2048/Game.cpp')
-rw-r--r-- | Userland/Games/2048/Game.cpp | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Games/2048/Game.cpp b/Userland/Games/2048/Game.cpp index ce827d29ff..5319ba41aa 100644 --- a/Userland/Games/2048/Game.cpp +++ b/Userland/Games/2048/Game.cpp @@ -187,7 +187,6 @@ static size_t get_number_of_free_cells(Game::Board const& board) Game::Board::SlideResult Game::Board::slide_tiles(Direction direction) { size_t successful_merge_score = 0; - Tiles new_tiles; switch (direction) { case Direction::Left: @@ -215,7 +214,11 @@ Game::Board::SlideResult Game::Board::slide_tiles(Direction direction) break; } - bool moved = new_tiles != m_tiles; + bool moved = false; + for (auto& t : m_sliding_tiles) { + if (t.row_from != t.row_to || t.column_from != t.column_to) + moved = true; + } return { moved, successful_merge_score }; } |