-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChase.py
More file actions
35 lines (29 loc) · 691 Bytes
/
Chase.py
File metadata and controls
35 lines (29 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import turtle
import random
# Set up the screen
win = turtle.Screen()
win.title("Turtle Chase Game")
win.bgcolor("lightblue")
# Create a turtle
t = turtle.Turtle()
t.shape("turtle")
t.color("green")
t.penup()
t.speed(0)
score = 0
speed = 1
# Function to move the turtle to a random position
def move_turtle(x, y): # Accepting x, y parameters
global score, speed
t.hideturtle()
t.goto(random.randint(-200, 200), random.randint(-200, 200))
t.showturtle()
score += 1
speed += 1
t.speed(speed)
print(f"Score: {score}")
# Function to start the game
def start_game():
t.onclick(move_turtle)
start_game()
win.mainloop()