Professional Documents
Culture Documents
MANDAL’S
PROJECT REPORT ON
Submitted by
DEPARTMENT OF COMPUTER
ENGINEERING B.L.PATIL
POLYTECHNIC, KHOPOLI,RAIGAD-
410203
[2020 –2021]
K.T.S.P. MANDAL’S
DEPARTMENT OF
COMPUTER
ENGINEERING
CERTIFICATE
This is to certify that the
seminar report entitled
Subject: - Python
Date: -
Place: - Khopoli
Abstract
Introduction
Methodology
Conclusion
Abstract
The project file contains python scripts (Pong.py). Talking about the gameplay,
the user has to strike back the moving ping ball towards the opponent court. If
he/she fails to touch the ball, then the opponent player wins that round. And the
game will be over after the 20 continuous wins of the same team. The pc control
of the game is also very simple. The left-side player has to use W and S keys to
move or slide the stick, while the right-side player has to use up and down arrow
keys. The gameplay design is so simple that the user won’t find it difficult to use
and understand.
Introduction
Ping Pong Game project is written in Python. The main objective of this game is to gain the
highest score. This game is an interesting addictive fun game. This is a human vs human two-
player game and the players have to play from both sides with the help of up and down keys.
The game ends whenever the player fails to touch the ball and it touches the other part of the
screen. Also, the player has to play the game turn-wise and use some strategy to win the
game. There is a simple and clean GUI for easy gameplay.
Methodology
Module
Turtle is the only module should be imported since this game is built on the top of turtle
module.
import turtle
Variables
Two variables must be declared to record scores of Pddle A and Paddle B.
score_a = 0
score_b = 0
Objects
Screen
screen = turtle.Screen()
screen.title("Pong")
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.tracer(0)
Paddle A
paddle_a = turtle.Turtle()
paddle_a.speed(0)
paddle_a.shape("square")
paddle_a.color("white")
paddle_a.shapesize(stretch_wid=5, stretch_len=1)
paddle_a.penup()
paddle_a.goto(-350, 0)
Paddle B
paddle_b = turtle.Turtle()
paddle_b.speed(0)
paddle_b.shape("square")
paddle_b.color("white")
paddle_b.shapesize(stretch_wid=5, stretch_len=1)
paddle_b.penup()
paddle_b.goto(350, 0)
Ball
ball = turtle.Turtle()
ball.speed(0)
ball.shape("circle")
ball.color("white")
ball.penup()
ball.goto(0, 0)
ball.dx = 0.1
ball.dy = -0.1
Pen
Pen is the object to record scores that gained by Paddle A and B.
pen = turtle.Turtle()
pen.speed(0)
pen.color("white")
pen.penup()
pen.hideturtle()
pen.goto(0, 260)
pen.write("Player A: 0 Player B: 0", align="center", font=("Courier", 20, "normal"))
Functions
Paddle A Up
def paddle_a_up():
y = paddle_a.ycor()
y += 30
paddle_a.sety(y)
Paddle A Down
def paddle_a_down():
y = paddle_a.ycor()
y -= 30
paddle_a.sety(y)
Paddle B Up
def paddle_b_up():
y = paddle_b.ycor()
y += 30
paddle_b.sety(y)
Paddle B Down
def paddle_b_down():
y = paddle_b.ycor()
y -= 30
paddle_b.sety(y)
Keyboard binding
screen.listen()
screen.onkeypress(paddle_a_up, "w")
screen.onkeypress(paddle_a_down, "s")
screen.onkeypress(paddle_b_up, "Up")
screen.onkeypress(paddle_b_down, "Down")
Code:
from random import choice, random
from turtle import *
def value():
"""Randomly generate value between (-5, -3) or (3, 5)."""
return (3 + random() * 2) * choice([1, -1])
ball = vector(0, 0)
aim = vector(value(), value())
state = {1: 0, 2: 0}
def draw():
"""Draw game and move pong ball."""
clear()
rectangle(-200, state[1], 10, 50)
rectangle(190, state[2], 10, 50)
ball.move(aim)
x = ball.x
y = ball.y
up()
goto(x, y)
dot(10)
update()
if x < -185:
low = state[1]
high = state[1] + 50
if x > 185:
low = state[2]
high = state[2] + 50
ontimer(draw, 50)
setup(420, 420, 370, 0)
hideturtle()
tracer(False)
listen()
onkey(lambda: move(1, 20), ‘w’)
onkey(lambda: move(1, -20), ‘s’)
onkey(lambda: move(2, 20), ‘I’)
onkey(lambda: move(2, -20), ‘k’)
draw()
done()
Output
Conclusion
The program seems ready to take on ping-pong and help coach a new generation of ping-pong players.
However, the perfect environment and a high-end camera are sadly a necessity; for now, it seems that
only time or a large amount of money will solve that issue