-
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
develop #1125
base: master
Are you sure you want to change the base?
develop #1125
Conversation
nineuito
commented
Jan 14, 2025
- DEMO LINK
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
const prevState = structuredClone(this.state); | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const row = this.state[i].filter((cell) => cell !== 0); | ||
|
||
for (let j = row.length - 1; j > 0; j--) { | ||
if (row[j] === row[j - 1]) { | ||
row[j] *= 2; | ||
this.score += row[j]; | ||
row.splice(j - 1, 1); | ||
j--; | ||
} | ||
} | ||
|
||
while (row.length < 4) { | ||
row.unshift(0); | ||
} | ||
this.state[i] = row; | ||
} | ||
|
||
if (prevState !== structuredClone(this.state)) { | ||
this.addRandomTile(); | ||
this.updateGameStatus(); | ||
} |
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, try to put it in a helper function and use it everywhere
…n the game class with handleMove
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.
good job, but don't add a new cell if the board didn't change
Screen.Recording.2025-01-15.at.12.03.48.mov
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.
Well done!!!