Pythonmic1 Final
Pythonmic1 Final
Micro
Project
on
Snake Game Using Python
Submitted in partial fulfillment of the requirement for the award of
Diploma of Engineering
in
Computer Engineering
By
Kushal Mali
Shubham Girnaik
Omkar Mestry
Harsh Chaudhari
April 2023
CERTIFICATE
76-Shubham Girnaik
77-Harsh Chaudhari
78-Omkar Mestry
80-Kushal Mali
PART –A PLAN
1 Brief Introduction 1
3 Resources Required 2
PART –B OUTCOMES
1 Brief Description
3
2 Aim of Micro-Project 4
PART-A PLAN
1.0 Brief Introduction
The snake is an arcade maze game that was created in the company of Gremlin Industries and published by Sega in the
month of October 1976. It is considered an excellent game and has been gaining popularity with the public for many
generations. The Snake game can be controlled with the four direction buttons in relation to the direction it's heading
into. The goal of playing the game is to score maximum points by grabbing food or fruits. The player is out of luck if
the snake strikes the wall or itself.
For beginners in Python and those seeking to create something simpler in their field can test this program. The module
called Turtle was specifically designed to be used for beginners to play with and submit a program of the project. This
project is written using Python 3.0.
Therefore, we will create a game that is based on Python with these modules.
o Turtle: This is an installed Python library that allows users to draw patterns and images by providing the user
with a virtual canvas.
o Time: It is used in order to calculate the number of seconds since the date of the event.
o Random: This is a function utilized to create random numbers in Python through the use of the random
module.
o The snake's body will expand body after eating the fruits.
o Colouring the snake's tail.
o When the fruit has been eaten, The score will then be recorded.
o Examining the snake's head for collides with body or side of the screen.
o The game will automatically restart immediately following the collision.
o A new design and shape of this fruit are revealed each time the window is opened.
o Scores will then be reset to zero, and the highest score will be kept until the window has not shut.
PART-BOUTCOME
The snake is an arcade maze game that was created in the company of Gremlin Industries and published by Sega in the
month of October 1976. It is considered an excellent game and has been gaining popularity with the public for many
generations. The Snake game can be controlled with the four direction buttons in relation to the direction it's heading
into. The goal of playing the game is to score maximum points by grabbing food or fruits. The player is out of luck if
the snake strikes the wall or itself.
For beginners in Python and those seeking to create something simpler in their field can test this program. The module
called Turtle was specifically designed to be used for beginners to play with and submit a program of the project. This
project is written using Python 3.0.
Therefore, we will create a game that is based on Python with these modules.
o Turtle: This is an installed Python library that allows users to draw patterns and images by providing the user
with a virtual canvas.
o Time: It is used in order to calculate the number of seconds since the date of the event.
o Random: This is a function utilized to create random numbers in Python through the use of the random
module.
o The snake's body will expand body after eating the fruits.
o Colouring the snake's tail.
o When the fruit has been eaten, The score will then be recorded.
o Examining the snake's head for collides with body or side of the screen.
o The game will automatically restart immediately following the collision.
o A new design and shape of this fruit are revealed each time the window is opened.
o Scores will then be reset to zero, and the highest score will be kept until the window has not shut.
We will create the display of this game, i.e., the screen of the game, where we'll create the snake's head and food items
for the snake to eat during the game and display the score at the top in the game. We'll verify the key that controls the
snake's movement. When we click on the terms commonly used in gaming, such as "e", "s", "f", and "v", we will be
able to control the snake's movement around the screen.
Code –
#importing libraries
import turtle
import random
import time
turtle.speed(5)
turtle.pensize(4)
turtle.penup()
turtle.goto(-310,250)
turtle.pendown()
turtle.color('black')
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.right(90)
turtle.forward(600)
turtle.right(90)
turtle.forward(500)
turtle.penup()
turtle.hideturtle()
#score
score = 0
delay = 0.1
#snake
snake = turtle.Turtle()
snake.speed(0)
snake.shape('square')
snake.color("black")
snake.penup()
snake.goto(0,0)
snake.direction = 'stop'
#food
fruit = turtle.Turtle()
fruit.speed(0)
fruit.shape('circle')
fruit.color('red')
fruit.penup()
fruit.goto(30,30)
old_fruit=[]
#scoring
scoring = turtle.Turtle()
scoring.speed(0)
scoring.color("black")
scoring.penup()
scoring.hideturtle()
scoring.goto(0,300)
scoring.write("Score :",align="center",font=("Courier",24,"bold"))
def snake_go_down():
if snake.direction != "up":
snake.direction = "down"
def snake_go_left():
if snake.direction != "right":
snake.direction = "left"
def snake_go_right():
if snake.direction != "left":
snake.direction = "right"
def snake_move():
if snake.direction == "up":
y = snake.ycor()
snake.sety(y + 20)
if snake.direction == "down":
y = snake.ycor()
snake.sety(y - 20)
if snake.direction == "left":
x = snake.xcor()
snake.setx(x - 20)
if snake.direction == "right":
x = snake.xcor()
snake.setx(x + 20)
# Keyboard bindings
screen.listen()
screen.onkeypress(snake_go_up, "Up")
screen.onkeypress(snake_go_down, "Down")
screen.onkeypress(snake_go_left, "Left")
screen.onkeypress(snake_go_right, "Right")
#main loop
while True:
screen.update()
#snake and fruit coliisions
if snake.distance(fruit)< 20:
x = random.randint(-290,270)
y = random.randint(-240,240)
fruit.goto(x,y)
scoring.clear()
score+=1
scoring.write("Score:{}".format(score),align="center",font=("Courier",24,"bold"))
delay-=0.001
## creating new_ball
new_fruit = turtle.Turtle()
new_fruit.speed(0)
new_fruit.shape('square')
new_fruit.color('red')
new_fruit.penup()
old_fruit.append(new_fruit)
old_fruit[index].goto(a,b)
if len(old_fruit)>0:
a= snake.xcor()
b = snake.ycor()
old_fruit[0].goto(a,b)
snake_move()
## snake collision
for food in old_fruit:
if food.distance(snake) < 20:
time.sleep(1)
screen.clear()
screen.bgcolor('turquoise')
scoring.goto(0,0)
scoring.write(" GAME OVER \n Your Score is
{}".format(score),align="center",font=("Courier",30,"bold"))
time.sleep(delay)
turtle.Terminator()
We Have Successfully Done Development of a application for an Single Player Snake Game
using PWP. Understanding of Python Language and different Concepts use in This Language.
Knowledge of user authentication and authorization systems. Special thanks to Nividha Mam for
her guidance and support in developing our PWP programming skills.