-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreboard.py
34 lines (26 loc) · 1.01 KB
/
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
class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.score = 0
self.highscore = 0
self.color("white")
self.penup()
self.hideturtle()
self.sety(275)
self.getHighScore()
self.write(f"Score: {self.score}\t High score: {self.highscore}", False, "center", ("Arial", 12, "bold"))
def update(self):
self.clear()
self.score += 1
self.write(f"Score: {self.score}\t High score: {self.highscore}", False, "center", ("Arial", 12, "bold"))
def getHighScore(self):
with open("highscore.txt") as file:
self.highscore = file.read()
def gameOver(self):
self.goto(0, 0)
self.write("GAME OVER!", False, "center", ("Arial", 12, "bold"))
with open("highscore.txt", "r+") as file:
if self.score > int(file.read()):
with open("highscore.txt", "w") as file:
file.write(str(self.score))