This is a simple game that measures how fast your reactions and reflexes are.
- The game starts when the player clicks the Start Game button.
- After that, the game shows a green box to the player after a random amount of time.
- The player has to click on the box as fast as possible in order to achieve a high score.
I've used:
- Tailwind CSS for styling.
- Vite for asset bundling.
- Vue 3 Composition API for the game logic and UI reactivity.
-
The
clickedproperty is used to check if the game is in progress or not, to prevent the user from spamming the start new game button, and also to prevent the user from starting a new game while a game is already running. -
The
initClickproperty is used to check if the game is the first game or not and to show the custom message to start the game or start a new game. -
The
toggleproperty is used to show and hide the green box. -
The
scoreproperty is used to record the time the player took to click the box. -
The
evaluationproperty is a calculated reactive property that's dependent on the score and calculated by theevaluateScore()helper function.- The
evaluateScore()function accepts the score and returns astringthat's based on the time elapsed.
- The
-
Based on whether it's the first game or not, we show a custom message to start the game or start a new game.
-
In order for our green box to show, we need a switch to toggle the show and hide states of the box.
- In our case, it's the
toggleproperty, abooleanthat'sfalseby default, therefore the box is hidden.
- In our case, it's the
-
When the player starts the game, the
ButtonClick()function is invoked.-
Inside this function, we set the
clickedproperty totrueand after a random amount of time generated by thegetRandomInt()helper function, we set thetoggleproperty totruetherefore, the box shows up. -
At the same time, we start a timer by recording the exact moment that the box showed using the
Date()class with thegetTime()method.
-
-
After the player clicks the box, we record the time he clicked in and calculate the elapsed time using this equation: [ t_{\text{final}} = t_{\text{end}} - t_{\text{start}}]
-
After calculating the
scorewe send it as a prop to theScoreBoardcomponent to show the score on the screen.- We don't show the score and evaluation unless the player has a score that's greater than zero
score > 0.
- We don't show the score and evaluation unless the player has a score that's greater than zero
-
In addition to showing the score, we evaluate the player's score based on a custom ranking system.
-
Then we set the
clickedproperty back tofalseand thetoggleproperty tofalseto hide the box. -
This cycle repeats for each new game.
- Installing frontend assets
npm install- Running the application
npm run dev