-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreBoard.py
More file actions
36 lines (30 loc) · 1.04 KB
/
ScoreBoard.py
File metadata and controls
36 lines (30 loc) · 1.04 KB
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
35
36
import os.path
from turtle import Turtle
ALIGNMENT = "center"
FONT = ("Arial", 12, "normal")
class ScoreBoard(Turtle):
def __init__(self):
super().__init__()
self.score = 0
self.high_score = 0
if os.path.exists("score.txt"):
with open("score.txt", mode='r') as file:
self.high_score = int(file.read())
else:
with open("score.txt", mode='w') as file:
file.write(str(self.high_score))
self.color("blue")
self.hideturtle()
self.penup()
self.goto(0, 230)
self.update_score()
def update_score(self):
self.clear()
with open("score.txt", mode='w') as file:
file.write(str(self.high_score))
self.write(f"Score: {self.score} High Score: {self.high_score}", align=ALIGNMENT, font=FONT)
def increase_score(self):
self.score += 1
if self.score > self.high_score:
self.high_score = self.score
self.update_score()