-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.py
31 lines (25 loc) · 906 Bytes
/
score.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
from turtle import Turtle
class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.score = 0
with open("file.txt") as file:
self.high_score = int(file.read())
self.color("white")
self.penup()
self.goto(0, 265)
self.update_scoreboard()
self.hideturtle()
def update_scoreboard(self):
self.clear()
self.write(f"Score: {self.score} High score: {self.high_score }", align="center", font=("Arial", 24, "normal"))
def increase_score(self):
self.score += 1
self.update_scoreboard()
def reset(self):
if self.score > self.high_score:
self.high_score = self.score
with open("file.txt", mode="w") as file:
file.write(f"{self.high_score}")
self.score = 0
self.update_scoreboard()