Python Project Report
Python Project Report
Python Project Report
On
“Python Programming”
Submitted By
Rohit Sonavane
(2209350328)
On the partial fulfilment for the Award of
Diploms in
INFORMATION TECHNOLOGY
Under the mentorship of
Mrs.Vaishali Chate
2.introduction
3.code
4.screenshots
5.conclusion
6.references
Abstract-
This project aims to bring the fun and simplicity of snake game with some new features. It will
include computer controlled intelligent opponents whose aim will be to challenge the human
players. It will also have the multiplayer feature that will allow more than one players to play
This project explores a new dimension in the traditional snake game to make it more
interesting and challenging. The simplicity of this game makes it an ideal candidate for a
minor project as we can focus on advanced topics like multiplayer functionality and
introduction-
Snake game is one of the most popular arcade games of all time. In this game, the main objective of
the player is to catch the maximum number of fruits without hitting the wall or itself. Creating a
snake game can be taken as a challenge while learning Python or Pygame. It is one of the best
beginner-friendly projects that every novice programmer should take as a challenge. Learning to
build a video game is kinda interesting and fun learning.
We will be using Pygame to create this snake game. Pygame is an open-source library that is
designed for making video games. It has inbuilt graphics and sound libraries. It is also beginner-
friendly, and cross-platform.
Code-
import turtle
import random
head = [0]
#score
a = [0]
b = [0]
#food coord
foodcoord = [0,0,0]
#cposition
cpos = []
def home(x,y):
x=0
y=0
a[0] = 0
b[0] = 0
head[0] = 0
foodcoord[2] = 0
cpos[:] = []
turtle.hideturtle()
turtle.clear()
turtle.pu()
turtle.color("red")
turtle.goto(0,0)
turtle.write("Play")
turtle.onscreenclick(start)
turtle.mainloop()
def window():
turtle.clear()
turtle.pu()
turtle.speed(0)
turtle.pensize(20)
turtle.color("black")
turtle.goto(-220,220)
turtle.pd()
turtle.goto(220,220)
turtle.goto(220,-220)
turtle.goto(-220,-220)
turtle.goto(-220,220)
turtle.pu()
turtle.goto(0,0)
def start(x,y):
turtle.onscreenclick(None)
window()
tfood = turtle.Turtle()
tfood.hideturtle()
tfood.pu()
tfood.speed(0)
tfood.shape("square")
tfood.color("red")
tscore = turtle.Turtle()
tscore.hideturtle()
tscore.pu()
tscore.speed(0)
tscore.goto(100,-250)
while x > -210 and x < 210 and y > -210 and y <210:
if foodcoord[2] == 0:
food(tfood)
foodcoord[2] = 1
turtle.onkey(u,"Up")
turtle.onkey(l,"Left")
turtle.onkey(r,"Right")
turtle.onkey(d,"Down")
turtle.listen()
move()
x = turtle.xcor()
y = turtle.ycor()
foodcoord[2] = 0
tfood.clear()
a[0] += 1
tscore.clear()
if len(cpos) > 1:
for i in range(1,len(cpos)):
tscore.clear()
tfood.clear()
gameover()
tscore.clear()
tfood.clear()
gameover()
#Food
def food(tfood):
x = random.randrange(-8,8,1)
y = random.randrange(-8,8,1)
foodcoord[0] = x
foodcoord[1] = y
tfood.hideturtle()
tfood.pu()
tfood.shape("square")
tfood.color("red")
tfood.goto(x*20,y*20)
tfood.stamp()
#Up
def u():
if head[0] == 270:
pass
else:
head[0] = 90
#Down
def d():
if head[0] == 90:
pass
else:
head[0] = 270
#Left
def l():
if head[0] == 0:
pass
else:
head[0] = 180
#Right
def r():
if head[0] == 180:
pass
else:
head[0] = 0
def move():
turtle.pensize(1)
turtle.color("green")
turtle.pu()
turtle.speed(3)
turtle.setheading(head[0])
turtle.shape("square")
turtle.stamp()
turtle.fd(20)
x = turtle.xcor()
y = turtle.ycor()
turtle.clearstamps(1)
cpos.insert(0,[round(x),round(y)])
cpos.pop(-1)
else:
cpos.insert(0,[round(x),round(y)])
b[0] += 1
def gameover():
turtle.onscreenclick(None)
turtle.speed(0)
turtle.pu()
turtle.goto(0,150)
turtle.color("red")
turtle.goto(0,50)
turtle.goto(200,-200)
turtle.write("Click to return",align="right",font=(0.0000001))
turtle.onscreenclick(home)
turtle.mainloop()
if name == 'main':
home(0,0)
Conclusion-
In conclusion, we have built a classic Snake Game using Python's tkinter module. The game consists
of a snake that moves around the canvas to collect food and avoid obstacles. Throughout the course
of this project, we used different programming concepts such as classes, functions, loops, and
events.
Additionally, we implemented features such as updating the score, increasing the game level, adding
obstacles, and restarting the game.
This is just one example of what can be done with Python, and there are endless possibilities for
what you can create.
Here's the link to the GitHub repository for this Snake Game in Python: Snake Game in Python . It
contains the complete source code for the system as well as detailed instructions on how to run it on
your local machine. Feel free to clone the repository, explore the code, and make any changes or
improvements you see fit.
References-
1.class lecture
2.https://www.geeksforgeeks.org/python-gui-tkinter/
3.https://www.tutorialspoint.com/python/python_gui
_programming.htm
4.https://www.pygame.org/news