-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreboard.py
More file actions
33 lines (27 loc) · 1008 Bytes
/
scoreboard.py
File metadata and controls
33 lines (27 loc) · 1008 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
from turtle import Turtle
ALIGN = "center"
FONT = ("Courier", 24, "normal")
class Score(Turtle):
def __init__(self):
super().__init__()
self.current_score = 0
with open("data.txt", mode="r") as data:
self.high_score = int(data.read())
self.pu()
self.color("white")
self.goto(0, 260)
self.hideturtle()
self.write(f"Score: {self.current_score} High Score: {self.high_score}", align=ALIGN, font=FONT)
def score_update(self):
self.clear()
self.write(f"Score: {self.current_score} High Score: {self.high_score}", align=ALIGN, font=FONT)
def reset(self):
if self.current_score > self.high_score:
self.high_score = self.current_score
with open("data.txt", mode="w") as data:
data.write(str(self.high_score))
self.current_score = 0
self.score_update()
def increase_score(self):
self.current_score += 1
self.score_update()