Jawahar Navodaya Vidyalaya Mavinakere, Hassan: Submitted by
Jawahar Navodaya Vidyalaya Mavinakere, Hassan: Submitted by
MAVINAKERE, HASSAN
INVESTIGATORY PROJECT
2021-22
TOPIC:
“TO CREATE A SNAKE GAME”
SUBMITTED BY:
NAME: JNANESHA KUMAR S.G
ROLL NO: 18164494
J N V M HASSAN
JAWAHAR NAVODAYA VIDYALAYA
MAVINAKERE, HASSAN
LAB CERTIFICATE
This project titled “TO CREATE A SNAKE
GAME”. Is bona field work of Master JNANESHA
KUMAR S.G of Roll.No: 18164494 of this
Vidyalaya. This project report is submitted of
AISSCE practical examination of 2021-22.
signature of signature of
Internal examiner external examiner
CONTENTS
ACKNOWLEDGEMENT
DECLARATION
AIM
INTRODUCTION
PYTHON CODE
OUTPUT
RESULT
BIBLIOGRAPHY
ACKNOLEDGEMENT
“TO CREATE
A
SNAKE GAME”
INTRODUCTION
It is a simple game in which
you have to move the snake
using the arrow keys in the
keyboard and help the snake to
find its food.
Use the arrow keys to change
the direction of the movement
of the snake. The score of the
user will be displayed on the
screen.
PYTHON CODE
#PROGRAM TO CREATE A SNAKE GAME
Import turtle
Import time
Import random
Delay=0.1
#score
Score=0
High_score=0
#SNAKE HEAD
head=turtle.turtle()
head.speed(0)
head.shape(”circle”)
head.colour(“yellow”)
head.penup()
head.goto(0,0)
head.direction = “stop”
#SNAKE FOOD
Food=turtle.turtle()
Food.speed(0)
Food.shape(“circle”)
Food.colour(“red”)
Food.penup()
Food.goto(0,100)
Segments=[]
#PEN
Pen=turle.turtle()
Pen.speed(0)
Pen.shape(“square”)
Pen.colour(“white”)
Pen.penup()
Pen.hideturtle()
Pen.goto(0,200)
Pen.write(“score:0 high score:0,align=”centre”, font=(“Courier”,24,”normal”))
Pen.goto(0,260)
Pen.write(“game by: jnaneshakumars.g”,align=”centre”,font=(“Times
new roman”,20,”normal”))
#FUNCTIONS
Def go_up():
If head.direction!=”down”:
Head.direction=”up”
Def go_down():
If head.direction!=”up”:
Head.direction=”down”
Def go_left():
If head.direction!=”right”:
Head.direction=”left”
Def go_right():
If head.direction!=”left”:
Head.direction=”right”
Def go_move():
If head.direction==”up”:
Y=head.ycor()
Head.sety(y+20)
If head.direction==”down”:
Y=head.ycor()
Head.sety(y-20)
If head.direction==”left”:
x=head.xcor()
Head.setx(x-20)
If head.direction==”right”:
x=head.xcor()
Head.setx(x+20)
#keyboard binding
Wn.listen()
Wn.onkeypress(go_up,”up”)
Wn.onkeypress(go_down,”down”)
Wn.onkeypress(go_left,”left”)
Wn.onkeypress(go_right,”right”)
#ADD A SEGMENT
New_segment = turtlr.turtle()
New_segment.speed(0)
New_segment.shape(“circle”)
New_segment.colour(“green”)
New_segment.penup()
Segments.append(new_segment)
If the score>high_score:
High_score=score
Pen.clear()
Pen.write(“score:{} high
score:{}.format(score,high_score,align=”centre,font+(“courier”,24,”norm
al”))
Time.sleep(delay)
Wn.mainloop()
OUTPUT
AFTER RUNNING THE PROGRAM, THE OUTPUT IS:
Result
The program
executed
without any
error(s)
BIBLIOGRAPHY