-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.py
53 lines (41 loc) · 1.26 KB
/
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from turtle import Turtle
class Scoreboard(Turtle):
format = {'align': 'center', 'font': ("Courier", 50, "bold")}
def __init__(self):
super().__init__()
self.color('white')
self.hideturtle()
self.speed('fastest')
self.penup()
self.l_score = self.r_score = 0
self.display_score()
def display_score(self):
self.clear()
self.goto(-100, 210)
self.write(self.l_score, **self.format)
self.setx(100)
self.write(self.r_score, **self.format)
def increase_score(self, winner: int):
# Left paddle win
if winner == 0:
self.l_score += 1
# Right paddle win
elif winner == 1:
self.r_score += 1
self.display_score()
def finalize(self):
if self.l_score == self.r_score:
l_color = r_color = 'light salmon'
elif self.l_score < self.r_score:
l_color = 'red'
r_color = 'lime'
else:
r_color = 'red'
l_color = 'lime'
self.clear()
self.goto(-100, 210)
self.color(l_color)
self.write(self.l_score, **self.format)
self.setx(100)
self.color(r_color)
self.write(self.r_score, **self.format)