-
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
2048 #1058
base: master
Are you sure you want to change the base?
2048 #1058
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.
Great job on implementing the 2048 game! 🎉 Your code meets the core requirements and effectively handles the game logic and UI updates. While there are some minor issues related to the initialization and use of this.board
, they do not significantly impact the overall functionality. Keep up the good work and consider addressing these points for even better code quality in the future! 😊
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
constructor( | ||
cells = [ | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
[0, 0, 0, 0], | ||
], |
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.
The constructor initializes this.cells
with the provided cells
parameter, but it seems that this.board
is used throughout the class for game operations. Ensure that this.board
is initialized properly, either in the constructor or in the restart
method, to avoid any undefined behavior.
let moved = false; | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const row = this.board[i].filter((val) => val !== 0); |
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.
The moveLeft
method uses this.board
, but the constructor initializes this.cells
. Ensure that this.board
is initialized correctly before using it in game logic.
let moved = false; | ||
|
||
for (let i = 0; i < 4; i++) { | ||
const row = this.board[i].filter((val) => val !== 0).reverse(); |
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.
Similar to moveLeft
, the moveRight
method uses this.board
. Ensure that this.board
is initialized correctly before using it in game logic.
const column = []; | ||
|
||
for (let row = 0; row < 4; row++) { | ||
if (this.board[row][col] !== 0) { |
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.
The moveUp
method also uses this.board
. Ensure that this.board
is initialized correctly before using it in game logic.
const column = []; | ||
|
||
for (let row = 0; row < 4; row++) { | ||
if (this.board[row][col] !== 0) { |
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.
The moveDown
method uses this.board
. Ensure that this.board
is initialized correctly before using it in game logic.
// const Game = require('../modules/Game.class'); | ||
// const game = new Game(); | ||
const Game = require('../modules/Game.class'); | ||
const game = new Game(); |
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.
Ensure that the Game
class is correctly initialized with the necessary parameters, especially if the constructor expects specific arguments. Currently, it is instantiated without any arguments, which might lead to issues if the class requires them.
startButton.addEventListener('click', () => { | ||
if (startButton.classList.contains('start')) { | ||
game.start(); | ||
updateBoard(); |
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.
Consider calling updateScore()
after game.start()
to ensure the score is reset and displayed correctly when the game starts.
game.moveLeft(); | ||
break; | ||
case 'ArrowRight': | ||
game.moveRight(); | ||
break; | ||
case 'ArrowUp': | ||
game.moveUp(); | ||
break; | ||
case 'ArrowDown': | ||
game.moveDown(); |
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.
After each move (left, right, up, down), ensure that the game state is updated correctly. The current implementation calls updateBoard()
, updateScore()
, and updateMessages()
after each move, which is correct. However, ensure that the Game
class methods (moveLeft
, moveRight
, etc.) are functioning as expected and updating the game state properly.
DEMO LINK