-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreboard.py
More file actions
45 lines (38 loc) · 1.32 KB
/
scoreboard.py
File metadata and controls
45 lines (38 loc) · 1.32 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
37
38
39
40
41
42
43
44
45
from turtle import Turtle
ALIGNMENT = "center"
FONT = ('Courier', 16, 'normal')
class ScoreBoard(Turtle):
def __init__(self):
super().__init__()
self.current_score = 0
self.penup()
self.hideturtle()
self.goto(0,260)
self.color('white')
with open("data.txt", "r") as file:
self.high_score = int(file.read())
self.refresh()
def game_start(self):
self.goto(0,0)
self.write('''Welcome: Press space to start!''', align=ALIGNMENT, font=FONT)
self.goto(0,260)
def reset(self):
if self.current_score > self.high_score:
self.high_score = self.current_score
with open("data.txt", "w") as file:
file.write(str(self.current_score))
self.current_score = 0
self.refresh()
def game_over(self):
self.clear()
self.goto(0,0)
self.write("GAME OVER! Click to exit!", align= ALIGNMENT, font= FONT)
self.goto(0,-20)
self.write("Press enter to replay!", align=ALIGNMENT, font=FONT)
def refresh(self):
self.clear()
self.goto(0, 260)
self.write(f"SCORE: {self.current_score} HIGH SCORE: {self.high_score}", align= ALIGNMENT, font= FONT)
def increase_score(self):
self.current_score += 1
self.refresh()