You are on page 1of 6

Muhammad Aziz

FINAL PROJECT
REPORT
Department of Computer System Engineering

University of Engineering & Technology Peshawar


Final Project Report Overall Status: Complete

Project Name: Snake Game in Python

1/2/2019

Snake Game:
Snake is a game where its body grows in length. There is no standard version of
the game. The concept originated in the 1976 arcade game Blockade, and its simplicity
has led to many implementations (some of which have the word snake or worm in the
title). After a variant was preloaded on Nokia mobile phones in 1998, there was a
resurgence of interest in the Snake concept as it found a larger audience.

Figure 1-Snake – The first published by Nokia, for monochrome phones. It was programmed in 1997 by Taneli Armanto of
Nokia and introduced on the Nokia 6110 .

Py-Game
Pygame is a cross-platform set of Python is an interpreted, high-level, general-purpose programming
Python modules designed for language. Created by Guido van Rossum and first released in 1991,
writing video games. It includes Python has a design philosophy that emphasizes code readability,
computer graphics and sound notably using significant whitespace. It provides constructs that
libraries designed to be used with enable clear programming on both small and large scales.
the Python programming
language.

Game Algorithm: All movement rating functions and evolutionary algorithm-based optimization. Abstract: Snake
game is a computer action game; whose goal is to control a snake to move and collect food in a map.

FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMAD AZIZ 1


Summery  Using Object Oriented Programing Language to approach the game implementation.
 Adding Colors and visual view to the gaming window.
 Snake is the common name for a video game concept where the player maneuvers a line which grows in
length, with the line itself being a primary obstacle.

Flow Chart  The flow chart of game is given in below fig.

Main function  Snake game is a computer action game, whose goal is to control a snake to move and collect food in a
map. In this game we develop a controller based on movement rating functions considering smoothness,
space, and food
 This simply imports the main game class that we’ll create momentarily, makes a new instance, and calls
the game.

FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMAD AZIZ 2


Snake Movement  We will once again utilize PyGame’s event handlers, this time to respond to the arrow keys to guide our
snake. Inside the Game.py file, add the following before our game loop inside the loop () function.

Game Area  The Whole game window is set to 500pixels.


 There are rows and columns in early console
 Later all the game window is modified to Plane display of multi-colors.

Colliding with the Wall  Let’s think talk this. So our original window, assuming you have kept the same settings, is 500 x 500, but there
is now a 35 pixel border on all four edges, effectively reducing our play area to 440 x 440. So these wi ll be the
dimensions we need to check for.

Creating food  Our snake can’t grow without having a steady supply of apples to eat. Let’s breakdown the requirements for
our apple.
 We will need an X and Y position at which to draw the apple
 A randomize function that will generate random coordinates on the playable game area as needed
 A draw function to display the apple

Eating Food  We will be utilizing the build in collision detection for PyGame rectangles to determine when an
apple has been eaten. We need to revise a few pieces of code to make this happen.

Increasing Size of Snake  The system we are going to use to keep track of the various body segments of the snake is going to
work by storing the last position of the head in an array, pushing to the top, each time the move
method of Snake is called.

Snake Colliding  To check if we have collided with ourselves, we do a cut and dry check where we iterate over each
with Itself body element and see if it has the same X and Y coordinate positions of the head.
 If so, this causes an error and restarts the game. This also works for trying to move the snake
backwards.

Conclusion  Our basic snake game is now playable and I hope you feel a lot more comfortable with PyGame and
game programming then you did before you read this article.

Colors, Config, and Magic  In game programming, it can be very easy for our code to begin to lose clarity. There are often
Numbers shapes or sprites being drawn at arbitrary X and Y coordinates, and those sprites often have
movement, colors, and animations. Next thing you know, you’ve got magic numbers and repeated
values spread out everywhere.

Initialization and the Game  Now that we know everything is working successfully so far, let’s next add the code to bootstrap
Loop PyGame and start our game loop. Let’s first add a bit of code to give our window a size and a title.

Issues  Installing IDE


 Implementation 1st time
 Adding graphics and level to game

FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMAD AZIZ 3


Movement toward food

Upward Motion Downward Motion


Movement only at Positive Y-axis Movement at Negative Y-axis

Figure 4-Down

Figure 2-Up

Rightward Motion
Movement only at positive X-axis
Leftward Motion
Movement only at negative X-axis

Figure 5-Right
Figure 3-Left

FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMAD AZIZ 4


Snake Body enlargement

After eating mean getting the food the length of snake increases.

Level 1 Snake length

Figure 6-Level 1

Level 2

Figure 7-Level 2

Level 3

Figure 8-Level 3

The end.

FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMAD AZIZ 5

You might also like