-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscoreboard.py
More file actions
40 lines (33 loc) · 1.25 KB
/
scoreboard.py
File metadata and controls
40 lines (33 loc) · 1.25 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
from turtle import Screen, _Screen, Turtle
from constants import DM
import os
__location__ = os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(__file__)))
class ScoreBoard(Turtle):
def __init__(self, screen: _Screen):
super().__init__()
self.score = 0
self.screen = screen
self.high_score = 0
self.writeText(f'Score: {self.score}')
with open(os.path.join(__location__, 'data.txt')) as file:
content = file.read()
self.high_score = int(content)
def increaseScore(self):
if(self.high_score < self.score+1):
self.high_score = self.score+1
with open(os.path.join(__location__, 'data.txt'), mode='w') as file:
file.write(str(self.score))
self.score += 1
self.writeText(f'Score: {self.score}. High Score: {self.high_score}')
def writeText(self, to_write: str):
self.reset()
self.penup()
self.goto((0, (DM/2)-60))
self.color('white')
self.hideturtle()
style = ('Courier', 13, 'normal')
self.write(to_write, font=style, align='center')
def resetScore(self):
self.score = 0
self.writeText(f'Score: {self.score}. High Score: {self.high_score}')