Skip to content

Commit

Permalink
final code rewiew 5
Browse files Browse the repository at this point in the history
  • Loading branch information
nikalaiii committed Dec 3, 2024
1 parent 9753694 commit 2d5e95d
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/modules/Game.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ class Game {
const newState = [0, 1, 2, 3].map((col) => {
const column = this.state
.map((row) => row[col])
.filter((cell) => cell !== 0); // Вибираємо колонку без нулів
.filter((cell) => cell !== 0);

for (let i = 0; i < column.length - 1; i++) {
if (column[i] === column[i + 1]) {
column[i] *= 2;
column[i + 1] = 0;
this.score += column[i]; // Додаємо очки
this.score += column[i];
}
}

Expand All @@ -254,7 +254,6 @@ class Game {
return [...compressed, ...Array(4 - compressed.length).fill(0)];
});

// Транспонуємо назад у формат рядків
this.state = [0, 1, 2, 3].map((row) => newState.map((col) => col[row]));

if (JSON.stringify(this.state) !== previousState) {
Expand Down

0 comments on commit 2d5e95d

Please sign in to comment.