-
Notifications
You must be signed in to change notification settings - Fork 0
/
scoreboard.py
44 lines (35 loc) · 1.17 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
from turtle import Turtle
ALIGNMENT = "center"
FONT = ("Courier", 80, "normal")
class Scoreboard(Turtle):
def __init__(self):
super().__init__()
self.hideturtle()
self.penup()
self.color("white")
self.l_score = 0
self.r_score = 0
self.update_scoreboard()
def update_scoreboard(self):
self.clear()
self.goto(-100, 200)
self.write(f"{self.l_score}", align=ALIGNMENT, font=FONT)
self.goto(100, 200)
self.write(f"{self.r_score}", align=ALIGNMENT, font=FONT)
def l_point(self):
self.l_score += 1
self.update_scoreboard()
def r_point(self):
self.r_score += 1
self.update_scoreboard()
def winner(self):
self.goto(0, 0)
if self.l_score == 7:
self.write(f"Left player is the winner!", align=ALIGNMENT, font=("Courier", 40, "normal"))
elif self.r_score == 7:
self.write(f"Right player is the winner!", align=ALIGNMENT, font=("Courier", 40, "normal"))
def game_over(self):
self.clear()
self.goto(0, 60)
self.write(f"GAME OVER", align=ALIGNMENT, font=FONT)
self.winner()