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

resolution game_2048 #1072

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

14lucas-mendes
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.

Thank you for your hard work on implementing the 2048 game! 🎮 While your solution is mostly on the right track, there are a few critical issues that need to be addressed to ensure the game functions correctly:

  1. Game State Management: The condition for allowing moves should be this.state === 'playing' instead of this.state !== 'idle'. This change is crucial for ensuring that moves are only allowed when the game is actively being played.

  2. Merge Logic: Both mergeUp and mergeDown functions need revision as they incorrectly create shallow copies of rows when they should be handling columns. This affects the core functionality of tile merging.

  3. DOM Element Selectors: There are several issues with the selectors in your script:

    • The selector for .field-cell should use document.querySelectorAll to select multiple elements.
    • The selector for message-start is missing a dot for class selection and should be .message-start.
    • The selector .buttom start should be .button.start to correctly select elements with both classes.
  4. Game Status Retrieval: The method game.status() does not exist. It should be game.getStatus() to correctly retrieve the game status.

  5. UI Message Handling: Ensure that messageLose is hidden when the game starts by using messageLose.classList.add('hidden');.

These issues are critical as they impact the game's core functionality and user interface. Once these are resolved, your implementation will be much stronger. Keep up the great work, and I look forward to seeing your improvements! 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review button in the Reviewers tab.

moveUp() {}
moveDown() {}
moveLeft() {
if (this.state !== 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition this.state !== 'idle' is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'.

}
}
moveRight() {
if (this.state !== 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition this.state !== 'idle' is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'.

}
}
moveUp() {
if (this.state !== 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition this.state !== 'idle' is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'.

}
}
moveDown() {
if (this.state !== 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition this.state !== 'idle' is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'.

}

function mergeDown(initialState) {
const result = initialState.map((col) => [...col]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mergeDown function creates a shallow copy of each row, which is unnecessary since you are working with columns. Consider revising this logic to correctly handle column merging.


// Write your code here
const gameScore = document.querySelector('.game-score');
const startButton = document.querySelector('.buttom start');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector '.buttom start' seems incorrect. It should likely be '.button.start' to correctly select the element with class 'button' and 'start'.

const startButton = document.querySelector('.buttom start');
const messageWin = document.querySelector('.message-win');
const messageLose = document.querySelector('.message-lose');
const messageStart = document.querySelector('message-start');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector 'message-start' is missing a dot for class selection. It should be '.message-start'.

const messageLose = document.querySelector('.message-lose');
const messageStart = document.querySelector('message-start');

const fields = document.querySelector('.field-cell');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The selector '.field-cell' should likely select multiple elements. Consider using document.querySelectorAll instead of document.querySelector.

}

// Ações de movimento apenas se o jogo estiver em progresso
if (game.status() === 'playing' && keyActions[e.key]) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method game.status() does not exist. It should be game.getStatus() to correctly retrieve the game status.


messageStart.classList.add('hidden');
messageWin.classList.add('hidden');
messageLose.classList.remove('hidden');

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The messageLose should be hidden when the game starts. Change messageLose.classList.remove('hidden'); to messageLose.classList.add('hidden');.

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.

Thank you for your submission! 🎉 While your implementation of the Game class for the 2048 game has several critical issues, approving this pull request will help you move forward in your learning journey. Here are the key areas to focus on for improvement:

  1. Game State Management: Ensure that moves are only allowed when the game is actively being played by using the condition this.state === 'playing'.

  2. Merge Logic: Implement the methods mergeToTheLeft, mergeToTheRight, mergeToTheUp, and mergeToTheDown to handle tile merging in all directions.

  3. Score Calculation: Implement the calculateScore method to update the score based on the game state changes.

  4. Game Status: Implement the loseWinState method to determine if the game is won or lost.

  5. Random Cell Addition: Correct the addNewCellRandomCell method to randomly add a new cell with a value of 2 or 4 to an empty spot.

  6. Initial State Usage: Correct the usage of initialState to properly handle the game board.

  7. DOM Interaction: Add necessary logic in main.js for DOM manipulation and event handling to interact with the UI.

Addressing these issues will significantly improve your game's functionality. Keep up the good work, and don't hesitate to reach out for help if needed. Happy coding! 🚀

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨


moveLeft() {
if (this.state === 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be this.state === 'playing' to ensure moves are only allowed when the game is actively being played.

return this.initialState;
}
moveRight() {
if (this.state === 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be this.state === 'playing' to ensure moves are only allowed when the game is actively being played.

return this.initialState;
}
moveUp() {
if (this.state === 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be this.state === 'playing' to ensure moves are only allowed when the game is actively being played.

return this.initialState;
}
moveDown() {
if (this.state === 'idle') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be this.state === 'playing' to ensure moves are only allowed when the game is actively being played.


// add metodo de atualização do tabuleiro quando se move para a direta
processMoveRight() {
const moveRows = this.initialState(this.mergeToTheRight);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect usage of initialState as a function. It should be this.initialState.map(this.mergeToTheRight).

mergeToTheLeft() {}

// mescla para a direita
mergeToTheRight() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method mergeToTheRight is not implemented. It should handle merging tiles to the right.

mergeToTheRight() {}

// mescla para cima
mergeToTheUp() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method mergeToTheUp is not implemented. It should handle merging tiles upwards.


// Add your own methods here
// mescla para baixo
mergeToTheDown() {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method mergeToTheDown is not implemented. It should handle merging tiles downwards.

@@ -1,7 +1,8 @@
'use strict';

// Uncomment the next lines to use your game instance in the browser
// const Game = require('../modules/Game.class');
// import Game from '../modules/Game.class.js';

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment this line to import the Game class from the specified module.

@@ -1,7 +1,8 @@
'use strict';

// Uncomment the next lines to use your game instance in the browser
// const Game = require('../modules/Game.class');
// import Game from '../modules/Game.class.js';

// const game = new Game();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment this line to create an instance of the Game class.

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.

3 participants