Name(s)_______________________________________________ Period ______ Date ___________________
| | Activity Guide - React Clicker Game | 🍎 | | :—- | :—- | :—- |
Overview
Build an interactive clicker game using React where players click randomly moving and sizing apples to earn points. Lose lives if you miss!
Model: Code.org Clicker Game
Try the Code.org clicker game linked above. Play for 2-3 minutes.
Discuss with a Partner:
State Variables: Fill in the table below for each piece of data your game needs to track.
| Variable Name | Initial Value | What It Stores |
|---|---|---|
| score | 0 | Player’s current score |
| lives | 3 | Number of lives remaining |
| appleSize | 100 | Current size of apple (pixels) |
| Â | Â | Â |
| Â | Â | Â |
Functions: List the functions you’ll need to create.
| Function Name | What It Does |
|---|---|
| clickTarget | Increases score, changes apple size/position |
| missTarget | Decreases lives, changes apple size/position |
| Â | Â |
| Â | Â |
Game Rules: Draw a flowchart or write pseudocode for the following:
Test Cases: Your game should handle these scenarios correctly.
| Action | Expected Behavior |
|---|---|
| Click apple at score 5 | Score increases to 6, apple moves |
| Miss apple at 3 lives | Lives decrease to 2, apple moves |
| Reach score of 100 | “You Win!” appears, apple disappears |
| Click apple when score < 100 | Lives stay the same (no penalty) |
Create React App:
npm create vite@latestcd clicker-gamenpm installnpm run devAdd Your Images:
apple.png)orchard.png)public/ folderFollow the level-by-level guide to build your game. Complete each level before moving to the next.
Core Features (Levels 1-11):
useState)Component Organization (Levels 12-13):
Polish & Documentation (Levels 14-17):
As You Code:
console.log() to debugPlay your game and verify it works correctly for all scenarios:
| Test | What to Check | âś“ |
|---|---|---|
| Click apple 5 times | Score = 5, apple moves each time | Â |
| Miss 3 times | Lives = 0 (or 3 → 0) |  |
| Apple size changes | Size varies between small and large | Â |
| Apple position changes | Apple appears in different locations | Â |
| Stats colors change | Colors change at scores 10, 20, 30 | Â |
| Reach 100 points | “You Win!” appears, apple disappears |  |
| Click background | Only lives decrease (not score) | Â |
Debug Using:
console.log() to check variable valuesevent.stopPropagation() temporarily to see event bubbling issueBefore you submit, check the rubric below to make sure your program meets the requirements.
| Category | Extensive Evidence | Convincing Evidence | Limited Evidence | No Evidence |
|---|---|---|---|---|
| React Setup | Vite + React project correctly set up and runs without errors. | Project mostly works but has minor setup issues. | Project has significant setup problems. | Project does not run. |
| State Management | All state variables (score, lives, appleSize, etc.) properly created with useState and updated correctly. |
Most state variables work correctly but some have issues. | Some state variables work but many have problems. | State is not used or doesn’t work. |
| Event Handling | Click handlers work correctly; event.stopPropagation() properly prevents event bubbling. |
Most events work but some trigger incorrectly. | Events partially work with significant issues. | Events don’t work or aren’t implemented. |
| Random Positioning | Apple size and position change randomly within game board boundaries after each interaction. | Random changes mostly work but occasionally go off-screen or fail. | Random changes partially work with frequent issues. | Random positioning not implemented or broken. |
| Win Condition | Win message appears at exactly 100 points; apple disappears correctly. | Win condition works but has minor issues. | Win condition partially works. | Win condition not implemented. |
| Component Structure | Stats and GameBoard components properly extracted with correct props. | Some components extracted but with issues. | Components attempted but poorly organized. | All code in one component. |
| Code Quality | Code is clean, readable, with good variable names and comments explaining key concepts. | Code is mostly readable with some comments. | Code is hard to follow with few comments. | Code is messy and unclear. |
| Styling | Game looks polished; images display correctly; colors change appropriately. | Game works visually but lacks polish. | Game has visual issues. | Game doesn’t display correctly. |
Minimum Requirements for Full Credit:
Answer the following questions about your project:
1. React Concepts:
Describe how you used the useState hook in your project. Why is useState necessary instead of using regular variables?
| Â |
|---|
| Â |
| Â |
2. Event Propagation:
Explain what event.stopPropagation() does in your code. What happens if you remove it?
| Â |
|---|
| Â |
| Â |
3. Component Composition:
Describe one component you extracted (Stats or GameBoard). What props does it receive and why?
| Â |
|---|
| Â |
| Â |
4. Debugging Experience:
What was the most challenging bug you encountered? How did you solve it?
| Â |
|---|
| Â |
| Â |
5. Creative Choices:
What images, colors, or features did you choose to personalize your game?
| Â |
|---|
| Â |
| Â |
Match the term with its definition:
| Term | Definition |
|---|---|
| State | Data that changes over time and triggers UI updates |
| Hook | Special React function like useState that adds features |
| Props | Data passed from parent component to child component |
| Event Handler | Function that runs when user interacts with element |
| Event Propagation | How events “bubble up” from child to parent elements |
| Component | Reusable piece of UI with its own logic and appearance |
Documentation:
Tools:
Help:
Project Complete! âś…
When finished, make sure to:
Good luck and have fun building your game! 🎮
Attribution: This activity guide was created with assistance from Claude AI (Anthropic).