-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscoreboard.py
35 lines (27 loc) · 904 Bytes
/
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
from turtle import Turtle
import random
with open("data.txt", mode='r') as game_data:
HIGH = int(game_data.read())
class ScoreBoard(Turtle):
def __init__(self):
super().__init__()
self.up()
self.hideturtle()
self.color("white")
self.score = 0
self.high_score = HIGH
self.update_score()
def update_score(self):
self.clear()
self.goto(-380, 360)
self.write(f"score : {self.score} High score : {self.high_score}", align="left", font=("arial", 20, "bold"))
def increase_score(self):
self.score += 8
self.update_score()
def reset_score(self):
if self.score > self.high_score:
self.high_score = self.score
self.score = 0
self.update_score()
with open("data.txt", mode="w") as write_data:
write_data.write(f"{self.high_score}")