Part 5: Game Logic
- Create a state to manage which View to display. You can use a boolean value to manage this state.
- pass the stateModifier as a prop to the
WelcomeViewcomponent and use it to update the state when the user clicks theStart Gamebutton. - Use the state to conditionally render the
WelcomeViewor theGameViewcomponent.
- you can use the ternary operator
.. ? .. : ..to conditionally render theWelcomeViewor theGameViewcomponents.
- Copy over the
RockPaperScissorsclass from the previous assignment and import it into theGameViewcomponent. TheRockPaperScissorsclass will be used to handle the game logic and determine the winner of the game. - Create different state hooks to manage the game state and the user's choice.
- userChoice
- userScore
- cpuScore
- gameHistory (an array to store the history of the game)
You will need to update those state values on Go click.
::: info This covers the big components of what we need to work on. Use those concepts to finish the game logic. :::