-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreboard.py
45 lines (37 loc) · 1.13 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
35
36
37
38
39
40
41
42
43
44
45
from turtle import Turtle
try:
score = int(open('highestScore.txt', 'r').read())
except FileNotFoundError:
score = open('highestScore.txt', 'w').write(str(0))
except ValueError:
score = 0
FONT = ('arial', 18, 'normal')
class Scoreboard(Turtle):
def __init__(self, lives):
super().__init__()
self.color('white')
self.penup()
self.hideturtle()
self.highScore = score
self.goto(x=-580, y=260)
self.lives = lives
self.score = 0
self.update_score()
def update_score(self):
self.clear()
self.write(f"Score: {self.score} | Highest Score: {self.highScore} | Lives: {self.lives}", align='left', font=FONT)
def increase_score(self):
self.score += 1
if self.score > self.highScore:
self.highScore += 1
self.update_score()
def decrease_lives(self):
self.lives -= 1
self.update_score()
def reset(self):
self.clear()
self.score = 0
self.update_score()
open('highestScore.txt', 'w').write(str(self.highScore))
def scoreboard_reset(self):
self.clear()