-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore.py
60 lines (43 loc) · 1.55 KB
/
score.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
from turtle import Turtle
class Score(Turtle):
new_user = True
def __init__(self):
super().__init__()
self.current_score = 0
self.highscore = 0
self.color("white")
self.hideturtle() #hide turtle cursor
self.show_score()
def show_score(self):
self.clear()
self.penup()
self.goto(-280, 230)
if self.new_user:
self.write(f"SCORE: {self.current_score}", False, align="left", font=('Arial', 8, 'bold'))
else:
self.write(f"HIGH SCORE: {self.highscore} SCORE {self.current_score}", False, align="left", font=('Arial', 8, 'bold'))
def increase_score(self):
self.current_score += 1
self.show_score()
def check_highscore(self):
if self.current_score > self.highscore:
self.highscore = self.current_score
self.current_score = 0
else:
self.current_score = 0
def reset_score(self):
pass
def gameover(self):
self.goto(0,0)
self.write(f"{"GAME OVER":>16}.\nPress Space to Play Again", False, align="center", font=('Arial', 15, 'normal'))
# if __name__ == "__main__":
# # read from file
# with open('file.txt') as file:
# content = file.read()
# print(content)
# # write to file
# with open('file1.txt', mode='w') as file:
# file.write("New content")
# #append to file
# with open('file2.txt', mode='a') as file:
# file.write("\n New line")