-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.py
32 lines (28 loc) · 887 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
ALIGNMENT = "center"
FONT = ('Terminal', 20, 'normal')
class Scoreboard(Turtle):
def __init__(self, position):
super().__init__()
self.hideturtle()
self.score=0
self.goto(position)
self.color("white")
self.write(f"{self.score}", align=ALIGNMENT, move=False,font=FONT)
# function to increment score
def add_score(self):
self.score += 1
self.refresh()
# function to refresh scoreboard
def refresh(self):
self.clear()
self.write(f"{self.score}", align=ALIGNMENT, move=False, font=FONT)
def game_over(self):
self.sety(0)
self.write("YOU WIN!", align=ALIGNMENT, font=FONT)
def is_winner(self,winning_score):
if self.score>=winning_score:
self.game_over()
return True
else:
return False