This document is a final project report for a Snake game created in Python. It summarizes the key aspects of developing the Snake game, including using Pygame for graphics and sound, storing the snake's segments in an array, generating random food locations, detecting collisions between the snake and food/walls, and increasing the snake's length when it eats food. It also provides flow charts and diagrams to illustrate the movement mechanics and different levels as the snake grows in size. Issues addressed during the project included installing development tools and adding graphics/levels to the game.
2. FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMADAZIZ 1
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–Thefirstpublished byNokia,for monochromephones.Itwasprogrammedin1997byTaneliArmantoof
Nokia and introduced ontheNokia 6110.
Py-Game
Pygame is a cross-platform set of
Pythonmodules designed for
writing video games. It includes
computer graphicsand sound
libraries designed to beused with
thePythonprogramming
language.
Pythonis an interpreted,high-level,general-purpose programming
language. Created by Guido van Rossum and first released in 1991,
Pythonhas a design philosophythat emphasizescodereadability,
notablyusing significant whitespace.It provides constructs that
enable clear programming on both small and large scales.
Game Algorithm: All movement rating functionsand evolutionary algorithm-based optimization. Abstract:Snake
game is a computeraction game; whosegoal is to controla snake to move andcollect foodin a map.
3. FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMADAZIZ 2
Summery Using Object Oriented Programing Language to approach the game implementation.
Adding Colors and visual view tothe gaming window.
Snake is the common name for a video game concept where the player maneuvers a line whichgrows in
length, withthe line itself being a primary obstacle.
Flow Chart The flow chart of game is givenin below fig.
Mainfunction Snake game is a computer action game, whose goal is to control a snake to move and collect food in a
map. Inthis game we developa controller based on movement rating functions considering smoothness,
space, and food
This simply imports the maingame class that we’ll create momentarily, makes a new instance, and calls
the game.
4. FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMADAZIZ 3
Snake Movement We will once againutilize PyGame’s event handlers, this time to respond to the arrow keys toguide our
snake. Inside the Game.py file, add the followingbefore 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 toPlane display of multi-colors.
Colliding withthe Wall Let’s think talk this. Soour original window, assumingyou have kept the same settings, is 500 x500, but there
is now a 35 pixel border on all four edges, effectively reducing our play area to 440 x440. Sothese will 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 needan 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 collisiondetection for PyGame rectangles to determine whenan
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 keeptrack of the various body segments of the snake is going to
work by storing the last position of the head in anarray, pushing to the top, each time the move
method of Snake is called.
Snake Colliding
withItself
Tocheck if we have collided withourselves, we do a cut and dry check where we iterate over each
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 alsoworks for trying to move the snake
backwards.
Conclusion Our basic snake game is now playable and I hope you feel a lot more comfortable withPyGame and
game programming then youdid before youread this article.
Colors, Config, and Magic
Numbers
In game programming, it can be very easy for our code to begin to lose clarity. There are often
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 magicnumbers and repeated
values spread out everywhere.
Initialization and the Game
Loop
Now that we know everything is working successfully sofar, let’s next add the code to bootstrap
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 togame
5. FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMADAZIZ 4
Movement toward food
UpwardMotion
Movement only at Positive Y-axis
Figure2-Up
LeftwardMotion
Movement only at negative X-axis
Figure3-Left
Downward Motion
Movement at Negative Y-axis
Figure4-Down
Rightward Motion
Movement only at positive X-axis
Figure5-Right
6. FINAL PROGRESS REPORT SNAKE GAME IN PYHTON MUHAMMADAZIZ 5
Figure8-Level 3
Snake Bodyenlargement
Aftereating mean getting the foodthe length ofsnake increases.
Level 1 Snake length
Figure6-Level 1
Level 2
Figure7-Level 2
Level 3
The end.