Closed Adrian-Moldovan closed 1 month ago
Update player position and mark tiles as visited on arrow key press
Created custom hook usePlayerMovement to handle player movement logic
useEffect
to manage key event listeners for player movementFix displaying the player position on the game start. Currently the starting map tile is unvisited.
@Miaana @DianaEP @RaresGherasim
Check the code on userPlayerMovement.jsx file. Upon pressing an arrow key, the setMap() state management should only be called if the player actually moves.
IMPLEMENTATION The event handler function code should first asses if the player can move (if the map allows it, if the player has the energy) and only then call the setMap() state handler should be be called
I would prefer to call separately the setMap() and setPlayer() state handlers - currently the setMap() calls the setPlayer() state handler. In my opinion, this implementation should describe more clearly the business logic layer.
Check if the logic can be placed in the Game.jsx file
Handling Player Movement (Requirement 1)
setMap
was called on every arrow key press, even if the player didn’t move.handlePlayerMove
is only triggered if the player actually changes position, reducing unnecessary updates.Separating setMap
and setPlayer
(Requirement 2)
setMap
also triggered setPlayer
, mixing state updates.setMap
and setPlayer
are called separately in Game.jsx
, making the logic cleaner and easier to follow.Moving Logic to Game.jsx
(Requirement 3)
usePlayerMovement
hook, making it harder to track.Game.jsx
, with usePlayerMovement
handling only key presses and movement triggers.@Miaana is on fire! Unstoppable!
DESCRIPTION
Pressing the arrow keys should change the player position by changing the map.playerPosition property. For now, we will not implement the energy level consumption and bonus / penalties after moving on a new tile.
REQUIREMENTS