-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
base: master
Are you sure you want to change the base?
resolution game_2048 #1072
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.
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:
-
Game State Management: The condition for allowing moves should be
this.state === 'playing'
instead ofthis.state !== 'idle'
. This change is crucial for ensuring that moves are only allowed when the game is actively being played. -
Merge Logic: Both
mergeUp
andmergeDown
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. -
DOM Element Selectors: There are several issues with the selectors in your script:
- The selector for
.field-cell
should usedocument.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.
- The selector for
-
Game Status Retrieval: The method
game.status()
does not exist. It should begame.getStatus()
to correctly retrieve the game status. -
UI Message Handling: Ensure that
messageLose
is hidden when the game starts by usingmessageLose.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.
src/modules/Game.class.js
Outdated
moveUp() {} | ||
moveDown() {} | ||
moveLeft() { | ||
if (this.state !== 'idle') { |
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 condition this.state !== 'idle'
is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'
.
src/modules/Game.class.js
Outdated
} | ||
} | ||
moveRight() { | ||
if (this.state !== 'idle') { |
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 condition this.state !== 'idle'
is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'
.
src/modules/Game.class.js
Outdated
} | ||
} | ||
moveUp() { | ||
if (this.state !== 'idle') { |
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 condition this.state !== 'idle'
is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'
.
src/modules/Game.class.js
Outdated
} | ||
} | ||
moveDown() { | ||
if (this.state !== 'idle') { |
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 condition this.state !== 'idle'
is incorrect. The game should only allow moves when the state is 'playing'. Change the condition to this.state === 'playing'
.
src/modules/Game.class.js
Outdated
} | ||
|
||
function mergeDown(initialState) { | ||
const result = initialState.map((col) => [...col]); |
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 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.
src/scripts/main.js
Outdated
|
||
// Write your code here | ||
const gameScore = document.querySelector('.game-score'); | ||
const startButton = document.querySelector('.buttom start'); |
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 selector '.buttom start' seems incorrect. It should likely be '.button.start' to correctly select the element with class 'button' and 'start'.
src/scripts/main.js
Outdated
const startButton = document.querySelector('.buttom start'); | ||
const messageWin = document.querySelector('.message-win'); | ||
const messageLose = document.querySelector('.message-lose'); | ||
const messageStart = document.querySelector('message-start'); |
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 selector 'message-start' is missing a dot for class selection. It should be '.message-start'.
src/scripts/main.js
Outdated
const messageLose = document.querySelector('.message-lose'); | ||
const messageStart = document.querySelector('message-start'); | ||
|
||
const fields = document.querySelector('.field-cell'); |
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 selector '.field-cell' should likely select multiple elements. Consider using document.querySelectorAll
instead of document.querySelector
.
src/scripts/main.js
Outdated
} | ||
|
||
// Ações de movimento apenas se o jogo estiver em progresso | ||
if (game.status() === 'playing' && keyActions[e.key]) { |
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 method game.status()
does not exist. It should be game.getStatus()
to correctly retrieve the game status.
src/scripts/main.js
Outdated
|
||
messageStart.classList.add('hidden'); | ||
messageWin.classList.add('hidden'); | ||
messageLose.classList.remove('hidden'); |
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 messageLose
should be hidden when the game starts. Change messageLose.classList.remove('hidden');
to messageLose.classList.add('hidden');
.
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.
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:
-
Game State Management: Ensure that moves are only allowed when the game is actively being played by using the condition
this.state === 'playing'
. -
Merge Logic: Implement the methods
mergeToTheLeft
,mergeToTheRight
,mergeToTheUp
, andmergeToTheDown
to handle tile merging in all directions. -
Score Calculation: Implement the
calculateScore
method to update the score based on the game state changes. -
Game Status: Implement the
loseWinState
method to determine if the game is won or lost. -
Random Cell Addition: Correct the
addNewCellRandomCell
method to randomly add a new cell with a value of 2 or 4 to an empty spot. -
Initial State Usage: Correct the usage of
initialState
to properly handle the game board. -
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') { |
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 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') { |
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 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') { |
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 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') { |
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 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); |
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.
Incorrect usage of initialState
as a function. It should be this.initialState.map(this.mergeToTheRight)
.
mergeToTheLeft() {} | ||
|
||
// mescla para a direita | ||
mergeToTheRight() {} |
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 method mergeToTheRight
is not implemented. It should handle merging tiles to the right.
mergeToTheRight() {} | ||
|
||
// mescla para cima | ||
mergeToTheUp() {} |
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 method mergeToTheUp
is not implemented. It should handle merging tiles upwards.
|
||
// Add your own methods here | ||
// mescla para baixo | ||
mergeToTheDown() {} |
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 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'; |
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.
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(); |
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.
Uncomment this line to create an instance of the Game
class.
DEMO LINK