-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.py
36 lines (28 loc) · 914 Bytes
/
scoreboard.py
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
from turtle import Turtle
ALIGNMENT = "center"
FONT = ("Courier", 22, "normal")
class ScoreBoard(Turtle):
def __init__(self):
super().__init__()
self.speed("fastest")
self.score = 0
with open("data.txt") as data:
self.high_score = int(data.read())
self.color("white")
self.penup()
self.goto(0, 270)
self.hideturtle()
self.update()
def increase_score(self):
self.score += 1
self.update()
def update(self):
self.clear()
self.write(f"Score:{self.score} High Score = {self.high_score}", move=False, align=ALIGNMENT, font=FONT)
def reset(self):
if self.score > int(self.high_score):
self.high_score = self.score
with open("data.txt", mode="w") as file:
file.write(f"{self.high_score}")
self.score = 0
self.update()