Closed Adrian-Moldovan closed 1 month ago
GameOver
component to display messages when the player finds the treasure or runs out of energy.Game
component to include the GameOver
component and manage the game state.usePlayerMovement
hook to handle energy management, checking for game over conditions after each move.tileEnergy
calculation and newPlayerEnergy
variable from the "Rares" branch to accurately manage player energy after each movement.generateTreasure
function from the "Rares" branch to ensure treasure is placed strategically on the map.@Miaana @DianaEP
The App.jsx implements the setGamePhase() state handler. The gamePhase property should determine what component is displayed (Settings, Game, GameOver).
Game-Over Logic in App.jsx:
App
, where updates to the player’s energy and position are passed from Game
and checked immediately.Game
sends real-time playerEnergy
and playerPosition
to App
through the onPlayerMove
function.
evaluateGameState
function always has the most up-to-date player info, so there are no delays in state updates.Utility Function Refactoring:
mapFactory
and playerFactory
were written inside the App
component, which made the code messier and less organized.Functions
folder to clean things up and keep utility code outside of the main app.App
component stay focused on managing the game state and flow.Simplified GameOver Component:
GameOver
had a useEffect
to check when the player’s energy hit zero or when the player found the treasure.useEffect
was removed, and GameOver
now just listens to the gamePhase
from App
.App
, so GameOver
only has to show the game-over screen and display the message it gets as a prop.
Either treasure is found or players has 0 energy
Implement the component for displaying the game over popup.