Pythonmic1 Final

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

A

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

under the guidance of

Mrs. Nividha Raut

Department of Computer Engineering

April 2023
CERTIFICATE

VIVA COLLEGE OF DIPLOMA ENGINEERING & TECHNOLOGY


VIRAR (W)
2022-23
This is to certify that the micro project entitled “Snake Game Using Python” has been
submitted under the guidance of Mrs.Nividha Raut in partial fulfillment of the requirement
for the award of Diploma of Engineering in Computer Engineering from Maharashtra State
Board of Technical Education.

“Snake Game Using Python”


GROUP MEMBERS

76-Shubham Girnaik
77-Harsh Chaudhari
78-Omkar Mestry
80-Kushal Mali

Project Guide H.O.D


Mrs.Nividha Raut Mr. Nikhil Asolkar
INDEX

Sr. No. Name of the topic Page no.

PART –A PLAN

1 Brief Introduction 1

2 Aim of the Micro-Project 2

3 Resources Required 2

PART –B OUTCOMES

1 Brief Description
3

2 Aim of Micro-Project 4

3 Course Outcomes Integrated 4

4 Actual Procedure Followed 5

5 Actual Resources Used


9

6 Outputs of the Micro-Projects 10

7 Skill Developed/ learning out of this Micro-Project 12


“Snake Game Using PWP” PWP 22616, Sem VI

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.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER


1
“Snake Game Using PWP” PWP 22616, Sem VI

2.0 AIM of Micro-Project

 To develop a Single Player Snake Game Using PWP


 To he 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.

3.0 Resources Required

Sr. No Name of Specification Qty Remarks


Resource
1. Computer Computer Intel dell RAM 8GB 1

Software IDLE(Python 3.11 6-bit)


2. 1
Any other Google and CMD
Resources
Used 1
3.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER


2
“Snake Game Using PWP” PWP 22619, Sem VI

PART-BOUTCOME

1.0 Brief Description

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.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER


3
“Snake Game Using PWP”
PWP 22616, Sem VI

2.0 AIM of Micro-Project

 To develop a Single Player Snake Game Using PWP


 To he 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.

3.0 Course Outcomes (CO)

a) Display message on Screen using Python Script on


IDL.
b) Develop Python Program to Demonsrate use of
Operators.
f) Hadle Exceptions

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 45


“Snake Game Using PWP”
PWP 22616, Sem VI

4.0 Procedure Followed

Algorithm for Single Player Snake Game Using PWP:

Step1- Installing Pygame.


Step 2- Create the Screen.
Step 3- Create the Snake.
Step 4- Moving the Snake.
Step 5- Game Over when Snake hits the boundaries.
Step 6- Adding the Food.
Step 7- Increasing the Length of the Snake.
Step 8- Displaying the Score.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 55


“Snake Game Using PWP”
PWP 22616, Sem VI

Flow Chart for Snake Game Using PWP:

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 65


“Snake Game Using PWP”
PWP 22616, Sem VI

Code –
#importing libraries
import turtle
import random
import time

#creating turtle screen


screen = turtle.Screen()
screen.title('SNAKE GAME')
screen.setup(width = 700, height = 700)
screen.tracer(0)
turtle.bgcolor('green')

##creating a border for our game

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'

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 75


“Snake Game Using PWP”
PWP 22616, Sem VI

#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"))

#######define how to move


def snake_go_up():
if snake.direction != "down":
snake.direction = "up"

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)

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 85


“Snake Game Using PWP”
PWP 22616, Sem VI

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)

#adding ball to snake

for index in range(len(old_fruit)-1,0,-1):


a = old_fruit[index-1].xcor()
b = old_fruit[index-1].ycor()

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 and border collision

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 95


“Snake Game Using PWP”
PWP 22616, Sem VI
if snake.xcor()>280 or snake.xcor()< -300 or snake.ycor()>240 or snake.ycor()<-240:
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"))

## 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()

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 5


10
“Snake Game Using PWP”
PWP 22616, Sem VI

5.0 Resources Required

Sr. No Name of Specification Qty Remarks


Resource
1. Computer Computer Intel dell RAM 8GB 1

Software IDLE(Python 3.11 64-bit) 1


2.
Any other Notepad and CMD
Resources
Used 1
3.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 5


11
“Snake Game Using PWP”
PWP 22616, Sem VI

6.0 Outputs of Micro-Projects

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 5


12
“ Snake Game Using PWP” PWP 22616, Sem VI

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 5


13
“Snake Game Using PWP” PWP 22616, Sem VI

7.0 Skill Developed

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.

VIVA COLLEGE OF DIPLOMA ENGG & TECH, COMPUTER 125


14

You might also like