-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreboard.py
More file actions
32 lines (26 loc) · 806 Bytes
/
Copy pathscoreboard.py
File metadata and controls
32 lines (26 loc) · 806 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
from turtle import Turtle
STARTING_TEXT = "Score : "
POSITION = (0,270)
ALIGNMENT = "center"
FONT = ("Courier", 20, "normal")
class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.score = 0
self.penup()
self.goto(POSITION)
self.color("white")
self.hideturtle()
self.update_score()
#Display current score
def update_score(self):
self.write(f"Score : {self.score}", align=ALIGNMENT, font=FONT)
#Increase score after food collision
def increase_score(self):
self.score += 1
self.clear()
self.update_score()
#Display game over message
def game_over(self):
self.goto(0,0)
self.write("Game Over.", align=ALIGNMENT, font=FONT)