0% found this document useful (0 votes)
677 views

Snake Game: Used HTML & Css Project Report With Source Code

The document is a project report on a "Snake Game" created by a group of students at Shree Samarath Polytechnic. It includes an index, acknowledgements, abstract, introduction, literature survey, system design, requirements, working algorithm, source code, and conclusions. The game was created using Python programming language to allow the user to control a snake's movement using arrow keys to eat food while avoiding obstacles and borders, with the goal of increasing the snake's length and the player's score.

Uploaded by

Arshiyan Sayyad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
677 views

Snake Game: Used HTML & Css Project Report With Source Code

The document is a project report on a "Snake Game" created by a group of students at Shree Samarath Polytechnic. It includes an index, acknowledgements, abstract, introduction, literature survey, system design, requirements, working algorithm, source code, and conclusions. The game was created using Python programming language to allow the user to control a snake's movement using arrow keys to eat food while avoiding obstacles and borders, with the goal of increasing the snake's length and the player's score.

Uploaded by

Arshiyan Sayyad
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 32

A

Project Report On

“Snake Game”

Maharashtra State Board Of Technical Education


(MSBTE)

Govt. of Maharashtra

Maharashtra State Board Of Technical Education, Mumbai

SHREE SAMARATH POLYTECHNIC BY

(2023-2024)

COMPUTER DEPARTMENT

Under The Guidance Of

Prof. Darode S.S.

Sr.No Group Member Enrollment No

1 Abhishek Sarojkumar Salve 2214660198


2 Arshiyan Munawar Sayyad 2114660018
3 Manoj Yashwant Jagatap 2114660028
4 Shrisant Sunil Badhe 2214660162
CERTIFICATAE
SHREE SAMARATH POLYTECHNIC

(Mhasane Phata-Parner, Ahmedngar)

SHREE SAMARATH POLYTECHNIC

This Is Certify That Capstone Project Report On

“Snake Game”
Sr.No Group Member Enrollment No

1 Abhishek Sarojkumar Salve 2214660198


2 Arshiyan Munawar Sayyad 2114660018
3 Manoj Yashwant Jagatap 2114660028
4 Shrisant Sunil Badhe 2214660162
Above student has been successfully completed this micro project
under the guidance of Prof.Darode S.S.

Date: / / .

Place: Mhasane Phata

Sub. Teacher HOD Principal


(Prof. Darode S.S.) (Prof. Darode S.S.) (Prof. Desale D.D.)
Project Report
(On Snake Game)

INDEX
Sr. Topics
No.
1 Acknowledgement
2 Abstract
3 Introduction
4 Literature Survey
5 System Design
6 System & Hardware
Requirements
7 Functional Requirements
8 Non-Functional
Requirments
9 Working Alogorithm
10 Source code
11 Sample Outputs
12 Conclusion
13 Future Scope
Acknowledgement
We would take this opportunity to express my sincere
thanks and gratitude to my teacher Mrs. Darode S.S. for his
vital support and guidance in completing this project.

We also express our gratitude to all the facility members,


parents and our fellow mates who have helped me in
making this project a success.
ABSTRACT
Snake game is a simple console application without
graphics. In this project, you can play the popular “Snake
Game” just like you played it elsewhere.You have to use
the up, down, right or left arrows to move the snake.
Foods are provided at the several co-ordinates of the
screen for the snake to eat.
Every time the snake eats the food, its length will by
increased by one element along with the score. I have used
Python as Programming language for writing the code for
the project and VS Code for writing the programs.
Operating system used Windows 11.
INTRODUCTION
Playing games is fun and exciting it gives us relief from
stress and unwind from our stressful works. Many of us
spend our vacant time or others that use most of their
time in playing and exploring new games. Today, with the
rapid development of technology we have, games that are
rising up together with it. Nowadays with the technology
we have many games that are developing for computer
most specifically for windows. With the high technology
equipped with these computers, computer games become
robust and attract many people to buy or have this gadget
for them to experience what's inside it which makes it a
trend for the new generation of gadget.

Snake game is a computer action game; whose goal is to


control a snake to move and collect food in a map. It has
been around since the earliest days of home computing
and has re-emerged in recent years on mobile phones.

It isn't the world's greatest game, but it does give you an


idea of what you can achieve with a simple python
program, and perhaps the basis by which to extend the
principles and create more interesting games on your
own.

To move the snake, use ‘up arrow' for up, 'down arrow'
for down, 'left arrow' for left and 'right arrow' for right.
Press 'Q' to exit the game at any time, press 'C' to continue
the game.

The aim of the game is to collect the dots (food) and avoid
the obstacles (crosses borders). As you collect the food,
the snake gets longer. The score also increases. There is no
concept of lives. Once you hit an obstacle, that's it, game
over.
LITERATURE SURVEY
The history of the Snake game goes back to the 1970's,
the concept originated in the 1976 arcade game Blockade,
and its simplicity has led to many implementations.
However, it was the 1980'swhen the game took on the
look that we will be using. It was sold under numerous
names and many platforms but probably gained
widespread recognition when it was shipped as standard
on Nokia mobile phones in the late 1990's. The first
published Nokia, for monochrome phones. It was
programmed in 1997 by Taneli Armanto of Nokia and
introduced on the Nokia 6110.The game involves
controlling a single block or snakehead by turning only left
or right by ninety degrees until you manage to eat an
block. When you get the block, the Snake grows an extra
block or body segment. If, or rather when, he snake bumps
into the edge other screen or accidentally eats himself the
game is over. The more blocks the snake eats the higher
the score.
SYSTEM DESIGN
To create a Snake game that allows users to control the
movement of a snake on a screen, to get points for eating
food and avoiding running into the walls or the growing
tail of the snake itself. In this problem, we want to write a
game where a graphical representation of a snake moves
across the screen.

When it encounters a piece of food, the snake grows


longer and we gain a point. If it hits the wall we die. To
write this program we are going to need:

 A way of representing the snake


 A way of representing the food
 A way to display the score,
 a way for our instructions to reach the snake,
 and a way to know when we've run into something
and died
Our system is going to involve working with both
hardware and software, and so we will need to understand
what we have available in hardware that can assist us.

If we build our software so that the snake is controlled by


directional arrows on the keyboard.

Now that understand how our hardware will work in the


design of our system, let's move on to starting the design
of our software system.
SYSTEM AND HARDWARE
REQUIREMENTS

SYSTEM REQUIREMENTS

OPERATING SYSTEM: WINDOWS XP or Higher

IDE: VisualStudio.NET 2005/2008

FRONT END: HTML

HARDWARE REQUIREMENTS
Intel P4 1.5GHz or above

512MB RAM

80GB HDD Minimum


FUNCTIONAL REQUIREMENTS
Here are the requirements (functional requirements) for
how the snake moves.

1. The snake must appear to move around the screen.

2. The snake must turn in response to user input.

3. The snake will increase in length if it eats food.

4. The snake will die if it runs into the walls.

5. The snake never stops moving.


NON-FUNCTIONAL REQUIREMENTS
The primary features of IT projects involve implementing
like an application, a piece of infrastructure, a patch. In
this specific context functional requirements tells us about
what project does when interacted, whereas non-
functional requirements describe about the bounds of
performance should be.

I. Robustness:

Robustness is nothing but its ability that it can tolerate the


affects of system functional body. And it can also be
defined as its systems ability that it can withstand to
change without transforming its initial stable
configuration II.

II. Reliability:

The system is trustworthy and it is consistently good in


performance. It can also be stated as the system performs
the function without any failure under certain conditions
and specified period of time.
III. Availability:

The system is available 24*7. Availability and Reliability


are directly proportional as reliability increase availability
also increases. The user can have access to the system all
the time.

IV. Reusability:

The system can be used any number of times by the


specific user. And the reusability is consistent, adaptable
and stable.

V. Effectiveness:

The algorithm is capable of producing desired result or it


has the ability to provide better results.
WORKING ALGORITHM

Let's look at how a program to run the whole game might


look:

 Draw the playing area with bounding rectangle, set


the counter to zero and display it.
 Draw the snake in a starting position.
 Draw the food in a starting location.
 On user input, change snake direction.
 Move the snake one move
 If the snake is over food, eat it, increase the score,
grow, move the food,
 Else if the snake is over in a wall, die.
 Go back to 4.
 Until the snake die.
SOURCE CODE
<html>

<head>

<title>Basic Snake HTML Game</title>

<meta charset="UTF-8">

<style>

html, body {

height: 100%;

margin: 0;

body {

background: Green;

display: flex;

align-items: center;

justify-content: center;

}
canvas {

border: 1px solid white;

</style>

</head>

<body>

<canvas width="400" height="400" id="game"></canvas>

<script>

var canvas = document.getElementById('game');

var context = canvas.getContext('2d');

// the canvas width & height, snake x & y, and the apple x &
y, all need to be a multiples of the grid size in order for
collision detection to work

// (e.g. 16 * 25 = 400)

var grid = 16;

var count = 0;
var snake = {

x: 160,

y: 160,

// snake velocity. moves one grid length every frame in


either the x or y direction

dx: grid,

dy: 0,

// keep track of all grids the snake body occupies

cells:[],

// length of the snake. grows when eating an apple

maxCells: 4

};

var apple = {
x: 320,

y: 320

};

// get random whole numbers in a specific range

// @see https://stackoverflow.com/a/1527820/2124254

function getRandomInt(min, max) {

return Math.floor(Math.random() * (max - min)) + min;

// game loop

function loop() {

requestAnimationFrame(loop);

// slow game loop to 15 fps instead of 60 (60/15 = 4)

if (++count < 4) {

return;
}

count = 0;

context.clearRect(0,0,canvas.width,canvas.height);

// move snake by it's velocity

snake.x += snake.dx;

snake.y += snake.dy;

// wrap snake position horizontally on edge of screen

if (snake.x < 0) {

snake.x = canvas.width - grid;

else if (snake.x >= canvas.width) {

snake.x = 0;

}
// wrap snake position vertically on edge of screen

if (snake.y < 0) {

snake.y = canvas.height - grid;

else if (snake.y >= canvas.height) {

snake.y = 0;

// keep track of where snake has been. front of the array is


always the head

snake.cells.unshift({x: snake.x, y: snake.y});

// remove cells as we move away from them

if (snake.cells.length > snake.maxCells) {

snake.cells.pop();

}
// draw apple

context.fillStyle = 'red';

context.fillRect(apple.x, apple.y, grid-1, grid-1);

// draw snake one cell at a time

context.fillStyle = 'Yellow';

snake.cells.forEach(function(cell, index) {

// drawing 1 px smaller than the grid creates a grid effect in


the snake body so you can see how long it is

context.fillRect(cell.x, cell.y, grid-1, grid-1);

// snake ate apple

if (cell.x === apple.x && cell.y === apple.y) {

snake.maxCells++;

// canvas is 400x400 which is 25x25 grids


apple.x = getRandomInt(0, 25) * grid;

apple.y = getRandomInt(0, 25) * grid;

// check collision with all cells after this one (modified


bubble sort)

for (var i = index + 1; i < snake.cells.length; i++) {

// snake occupies same space as a body part. reset game

if (cell.x === snake.cells[i].x && cell.y ===


snake.cells[i].y) {

snake.x = 160;

snake.y = 160;

snake.cells = [];

snake.maxCells = 4;

snake.dx = grid;

snake.dy = 0;
apple.x = getRandomInt(0, 25) * grid;

apple.y = getRandomInt(0, 25) * grid;

});

// listen to keyboard events to move the snake

document.addEventListener('keydown', function(e) {

// prevent snake from backtracking on itself by checking that


it's

// not already moving on the same axis (pressing left while


moving

// left won't do anything, and pressing right while moving


left

// shouldn't let you collide with your own body)


// left arrow key

if (e.which === 37 && snake.dx === 0) {

snake.dx = -grid;

snake.dy = 0;

// up arrow key

else if (e.which === 38 && snake.dy === 0) {

snake.dy = -grid;

snake.dx = 0;

// right arrow key

else if (e.which === 39 && snake.dx === 0) {

snake.dx = grid;

snake.dy = 0;

// down arrow key

else if (e.which === 40 && snake.dy === 0) {


snake.dy = grid;

snake.dx = 0;

});

// start the game

requestAnimationFrame(loop);

</script>

</body>

</html>
SAMPLE OUTPUTS
CONCLUSION

The project in python programming of Snake Game is a


simple console application with very simple graphics. In
this project, you can play the popular "Snake Game" just
like you played it elsewhere. You have to use the up, down,
right, or left arrows to move the snake.

Foods are provided at the several co-ordinates of the


screen for the snake to eat. Every time the snake eats the
food, its length will increased by one element along with
the score.

It isn't the world's greatest game, but it does give you an


idea of what you can achieve with a relatively simple
HTML programming and perhaps the basis by which to
extend the principles and create more interesting games
on your own.
FUTURE SCOPE
In this project, I have used simple application, this project
will be able to implement in future after making some
changes and modifications as made this project at low
level.

The modifications that can be done in this project are:

 It can be made with good graphics.


 We can add more options like Top scores and Player
Profile.
 We can add multiplayer option.
REFERENCE:

1) https://data-flair.training/blogs/snake-game-python-
program/

References:

✓Class Lecture

✓https://www.youtube.com/watch?v=rFFVyNn9 8A

✓http://www.c
sharpcorner.com/UploadFile/@salve/snake-game-
application-in-C-Sharp/

✓http://www.dreamincode.net/forums/topic/243537-
control-issue- with-snake-game-in-c%23/

✓http://csharp.net-
informations.com/communications/csharp-chat-
client.html

You might also like