-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDart.py
More file actions
38 lines (32 loc) · 744 Bytes
/
Dart.py
File metadata and controls
38 lines (32 loc) · 744 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
36
37
38
import turtle
import random
# Set up the screen
win = turtle.Screen()
win.title("Turtle Darts Game")
win.bgcolor("lightblue")
# Create the dartboard
dartboard = turtle.Turtle()
dartboard.shape("circle")
dartboard.color("red")
dartboard.shapesize(10)
dartboard.penup()
dartboard.goto(0, 0)
# Create the dart
dart = turtle.Turtle()
dart.shape("triangle")
dart.color("black")
dart.penup()
score = 0
# Function to throw the dart
def throw_dart(x, y):
global score
dart.goto(x, y)
distance = dart.distance(0, 0)
if distance < 100:
score += int((100 - distance) / 10)
else:
score -= 5
print(f"Score: {score}")
# Start the game
win.onclick(throw_dart)
win.mainloop()