Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

2048 #1058

wants to merge 1 commit into from

Conversation

ErasoumZe
Copy link

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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! ✨

Comment on lines +19 to +25
constructor(
cells = [
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 0],
],

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);

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();

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) {

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) {

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();

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();

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.

Comment on lines +85 to +94
game.moveLeft();
break;
case 'ArrowRight':
game.moveRight();
break;
case 'ArrowUp':
game.moveUp();
break;
case 'ArrowDown':
game.moveDown();

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants