-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable.py
41 lines (36 loc) · 1.4 KB
/
table.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
from turtle import Turtle, Screen
SCREEN_WIDTH = 1200
SCREEN_HEIGHT = 600
BG_COLOR = 'black'
class Table:
"""A class to manage to table (screen) in Pong."""
def __init__(self):
"""Initialize the attributes of the table."""
self.screen = Screen()
self.screen.setup(SCREEN_WIDTH, SCREEN_HEIGHT)
self.screen.bgcolor(BG_COLOR)
self.screen.tracer(0)
self.screen.title("Pong!")
self.draw_net()
self.draw_boundary()
def draw_net(self):
"""Draws the turtle objects representing the net of the Pong table."""
for i in range(1, int(SCREEN_HEIGHT / 50)):
net = Turtle(shape='square')
net.penup()
net.color('light yellow')
net.shapesize(stretch_wid=1.5, stretch_len=0.3)
net.setpos(0, 0.5 * self.screen.window_height() - 50 * i)
def draw_boundary(self):
"""Draws the boundaries of the table."""
boundary = Turtle('square')
boundary.color('light yellow')
boundary.pensize(10)
boundary.penup()
boundary.setpos(-0.50 * self.screen.window_width(), 0.49 * self.screen.window_height())
boundary.pendown()
boundary.forward(SCREEN_WIDTH)
boundary.penup()
boundary.setpos(-0.50 * self.screen.window_width(), -0.48 * self.screen.window_height())
boundary.pendown()
boundary.forward(SCREEN_WIDTH)