-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Game 2048 #1093
base: master
Are you sure you want to change the base?
Game 2048 #1093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/modules/Game.class.js
Outdated
}); | ||
|
||
if (hasWinningCell) { | ||
return 'win'; // Игрок выиграл |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments
return 'win'; // Игрок выиграл | |
return 'win'; |
src/modules/Game.class.js
Outdated
if (arr[i] === arr[i + 1]) { | ||
const mergedValue = arr[i] * 2; | ||
|
||
result.push(mergedValue); // Удваиваем значение |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comments everywhere
result.push(mergedValue); // Удваиваем значение | |
result.push(mergedValue); |
src/modules/Game.class.js
Outdated
const previousBoard = this.getState(); | ||
|
||
const transposedBoard = this.transpose(this.board); | ||
|
||
transposedBoard.forEach((row, index) => { | ||
const nonZeroElements = row.filter((value) => value !== 0); | ||
const combinedRow = this.joinValues(nonZeroElements, row.length); | ||
|
||
transposedBoard[index] = combinedRow; | ||
}); | ||
|
||
this.board = this.transpose(transposedBoard); | ||
|
||
if (this.isBoardChanged(previousBoard, this.board)) { | ||
const randomCell = this.getRandomCell(1); | ||
|
||
this.addNewCell(randomCell); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is similar in every method, so it would be better to move it to a helper function and use it everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amazing
DEMO LINK