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
WelcomeView
component and use it to update the state when the user clicks theStart Game
button. - Use the state to conditionally render the
WelcomeView
or theGameView
component.
- you can use the ternary operator
.. ? .. : ..
to conditionally render theWelcomeView
or theGameView
components.
- Copy over the
RockPaperScissors
class from the previous assignment and import it into theGameView
component. TheRockPaperScissors
class 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. :::