- Open
week12.pyin Thonny - Press Run (F5)
- Click on the red circle with your mouse to collect points
- Try to get a score of at least 10 before time runs out
- Challenge: Can you beat 15 points?
-
Change game duration
- Find:
GAME_SECONDS = 25 - Try:
GAME_SECONDS = 30(more time) - Try:
GAME_SECONDS = 15(harder challenge)
- Find:
-
Change target appearance
- Find:
target.color("red") - Try:
target.color("blue")or other colors - Find:
target.shape("circle") - Try:
target.shape("square")ortarget.shape("triangle")
- Find:
-
Make target bigger or smaller
- After creating target, add:
target.shapesize(2, 2) # Bigger (easier) # or target.shapesize(0.7, 0.7) # Smaller (harder)
-
Change click tolerance
- Find:
if target.distance(x, y) < 25: - Try:
< 40(easier - more forgiving clicks) - Try:
< 15(harder - need precise clicks)
- Find:
-
Change update speed
- Find:
screen.ontimer(tick, 250) - Try:
screen.ontimer(tick, 100)(updates faster - smoother) - Try:
screen.ontimer(tick, 500)(updates slower)
- Find:
-
Show final score
def tick(): if time_up(): writer.goto(-120, 20) writer.write("TIME UP!", font=("Arial", 24, "bold")) writer.goto(-100, -20) writer.write(f"Final Score: {score}", font=("Arial", 18, "normal")) return draw_ui() screen.ontimer(tick, 250)
-
Add a win condition
- Win if score reaches 20:
def on_click(x, y): global score if time_up(): return if target.distance(x, y) < 25: score += 1 if score >= 20: # Win! writer.goto(-70, 0) writer.write("YOU WIN!", font=("Arial", 24, "bold")) return move_target() draw_ui()
-
Shrinking target challenge
- Target gets smaller as you score more:
def on_click(x, y): global score if time_up(): return if target.distance(x, y) < 25: score += 1 move_target() # Shrink target size = max(0.5, 1.5 - (score * 0.05)) target.shapesize(size, size) draw_ui()
-
Add miss penalty
- Clicking and missing decreases score:
def screen_click(x, y): global score if time_up(): return if target.distance(x, y) < 25: score += 1 move_target() else: score = max(0, score - 1) # Lose point for missing draw_ui() # Replace target.onclick with: screen.onclick(screen_click)
-
Multiple targets
- Create 3 targets worth different points:
# Create multiple targets targets = [] colors = ["red", "blue", "green"] points = [1, 2, 3] # Different point values for i in range(3): t = turtle.Turtle() t.shape("circle") t.color(colors[i]) t.penup() t.goto(random.randint(-320, 320), random.randint(-200, 200)) targets.append(t) def check_click(x, y): global score if time_up(): return for i, target in enumerate(targets): if target.distance(x, y) < 25: score += points[i] # Add corresponding points target.goto(random.randint(-320, 320), random.randint(-200, 200)) draw_ui() break screen.onclick(check_click)
-
Moving targets
- Targets move on their own:
target_vx = 5 # Velocity in X direction target_vy = 3 # Velocity in Y direction def tick(): global target_vx, target_vy if time_up(): writer.goto(-90, 0) writer.write("TIME UP!", font=("Arial", 24, "bold")) return # Move target new_x = target.xcor() + target_vx new_y = target.ycor() + target_vy # Bounce off walls if new_x < -330 or new_x > 330: target_vx = -target_vx if new_y < -230 or new_y > 230: target_vy = -target_vy target.goto(new_x, new_y) draw_ui() screen.ontimer(tick, 50) # Faster updates for movement
-
Difficulty selector
- Choose difficulty at start:
print("Choose difficulty:") print("1 = Easy (30s, big target)") print("2 = Normal (25s, normal target)") print("3 = Hard (15s, small target)") choice = input("Enter 1, 2, or 3: ") if choice == "1": GAME_SECONDS = 30 target.shapesize(2, 2) elif choice == "3": GAME_SECONDS = 15 target.shapesize(0.6, 0.6) else: GAME_SECONDS = 25
-
Countdown at start
- Add 3-2-1-GO countdown:
def countdown(): writer.goto(-50, 0) for i in range(3, 0, -1): writer.clear() writer.write(str(i), font=("Arial", 48, "bold")) time.sleep(1) writer.clear() writer.write("GO!", font=("Arial", 48, "bold")) time.sleep(0.5) writer.clear() writer.goto(-330, 210) countdown() start_time = time.time() # Start timing after countdown tick()
-
High score system
- Track and display best score:
high_score = 0 def tick(): global high_score if time_up(): if score > high_score: high_score = score writer.goto(-120, 30) writer.write("TIME UP!", font=("Arial", 24, "bold")) writer.goto(-140, 0) writer.write(f"Score: {score}", font=("Arial", 18, "normal")) writer.goto(-140, -30) writer.write(f"High Score: {high_score}", font=("Arial", 16, "normal")) return draw_ui() screen.ontimer(tick, 250)
-
Add a title screen
- Show game name at start
- Add your name as creator
- Add brief instructions
-
Polish the visual design
- Choose a color theme
- Add a background color:
screen.bgcolor("lightblue") - Consistent font styling
-
Test thoroughly
- Play 5 games
- Note any bugs
- Get feedback from a friend
-
Document your enhancements
- What modifications did you make?
- Why did you make those choices?
- What was challenging?
- I can click targets and score points
- I understand how onclick() works
- I understand how ontimer() creates the game loop
- I added at least two enhancements from Task C or D
- My game is polished and ready to present
- I can explain my code to someone else