Skip to content

Commit 855b3a7

Browse files
authored
all part uploaded of ping pong game
1 parent 0ae4205 commit 855b3a7

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

ping_pong/ball.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from turtle import Turtle
2+
3+
class Ball(Turtle):
4+
def __init__(self):
5+
super().__init__()
6+
self.xmove = 10
7+
self.ymove = 10
8+
self.penup()
9+
self.shape("circle")
10+
self.color("white")
11+
12+
13+
def move(self):
14+
new_x=self.xcor()+self.xmove
15+
new_y = self.ycor() + self.ymove
16+
self.goto(new_x,new_y)
17+
18+
def bounce(self):
19+
self.ymove *= -1
20+
21+
def bounce_pad(self):
22+
self.xmove *= -1
23+
def refresh(self):
24+
self.goto(0,0)
25+
self.xmove *=-1
26+
self.ymove *=-1
27+

ping_pong/paddle.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from turtle import Turtle,Screen
2+
3+
class Paddle(Turtle):
4+
5+
def __init__(self):
6+
super().__init__()
7+
8+
def create_bars(self,position):
9+
self.penup()
10+
self.color("white")
11+
self.shape("square")
12+
self.shapesize(stretch_len=1, stretch_wid=6)
13+
self.goto(position)
14+
15+
def down(self):
16+
y_cor=self.ycor()-30
17+
self.goto(self.xcor(),y_cor)
18+
19+
def up(self):
20+
y_cor = self.ycor() + 30
21+
self.goto(self.xcor(), y_cor)
22+
23+

ping_pong/scoreboard.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from turtle import Turtle
2+
3+
class Scoreboard(Turtle):
4+
def __init__(self):
5+
super().__init__()
6+
self.total_r=0
7+
self.total_l=0
8+
self.penup()
9+
self.hideturtle()
10+
self.color("white")
11+
self.goto(0,250)
12+
13+
def update(self):
14+
self.clear()
15+
self.write(f"{self.total_l} {self.total_r}", align="center", font=("Courier", 26, "normal"))

0 commit comments

Comments
 (0)