siit-webdev-47 / treasure-hunt-game

1 stars 0 forks source link

Moving the player should re-render the map #11

Closed Adrian-Moldovan closed 1 month ago

Adrian-Moldovan commented 4 months ago

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

Miana-Neagos commented 4 months ago

Update player position and mark tiles as visited on arrow key press

Miana-Neagos commented 4 months ago

Created custom hook usePlayerMovement to handle player movement logic

Adrian-Moldovan commented 4 months ago

Fix displaying the player position on the game start. Currently the starting map tile is unvisited.

Adrian-Moldovan commented 3 months ago

@Miaana @DianaEP @RaresGherasim

REQUIREMENT 1

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

REQUIREMENT 2

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.

REQUIREMENT 3

Check if the logic can be placed in the Game.jsx file

Miana-Neagos commented 2 months ago
  1. Handling Player Movement (Requirement 1)

    • Before: setMap was called on every arrow key press, even if the player didn’t move.
    • After: handlePlayerMove is only triggered if the player actually changes position, reducing unnecessary updates.
  2. Separating setMap and setPlayer (Requirement 2)

    • Before: setMap also triggered setPlayer, mixing state updates.
    • After: setMap and setPlayer are called separately in Game.jsx, making the logic cleaner and easier to follow.
  3. Moving Logic to Game.jsx (Requirement 3)

    • Before: Most game logic was in the usePlayerMovement hook, making it harder to track.
    • After: The main logic is now in Game.jsx, with usePlayerMovement handling only key presses and movement triggers.
Adrian-Moldovan commented 2 months ago

@Miaana is on fire! Unstoppable!