Mushir CSS
Mushir CSS
“Snake Game”
Program & Program code : CO-5I
Course : Client Side Scripting(CSS)
Course code 22519
Submitted by,
MSBTE, Mumbai.
Academic Year: 2024-25
CERTIFICATE
This is to certify that the micro project report entitled
“Snake Game”
Submitted by,
Of semester V institute, Sau. Sundarabai Manik Adsul Polytechnic, Chas, Ahmednagar (code:
1464) has completed the micro project satisfactorily in course CSS(22519) for the Academic year
2023-24 as prescribed in the MSBTE curriculum.
I take this opportunity to acknowledgement the constant encouragement and continuous help give
to me by my guide Prof. PADIR J.D I convey my sincere thanks to his valuable timely
I would also like to thanks Principal Prof. Gadakh.R.S. And Head of department Prof: Hole P.P. I
would also like to thank teaching staff of department for achieving this goal.
I also thankful to those think which are directly or indirectly help me for completion this micro
project finally. I thank my parents without whose supports; the completion of the project would not have
been possible.
3. Action plan
4. Resources required
7. Source code
8. Output
9 Conclusion
1. Introduction
JavaScript is a dynamic and versatile programming language that has become an integral part
of the modern web. It is the cornerstone of interactive web development, allowing developers
to bring websites to life with rich, engaging user experiences. In this introduction, we'll explore
the fundamentals and significance of JavaScript, a language that has reshaped the way we
interact with the digital world.
Welcome to the captivating world of our Microproject, an exciting adventure into the realm of
classic gaming. In this project, we present to you the timeless and enthralling Snake Game.
Whether you're a seasoned gamer looking for a nostalgic trip down memory lane or a budding
programmer eager to explore the fundamentals of game development, you're in for a treat.
The main aim of the Snake Game is to control a snake on the game board and guide it to
consume food items while avoiding collisions with the walls of the game area and, most
importantly, with its own tail. The objectives of the game can be summarized as follows :
1.Eating Food: The primary goal is to guide the snake to eat the food items (often
represented as dots or other symbols) that appear on the game board. Each time the snake
consumes a piece of food, it grows longer.
2.Growing the Snake: As the snake eats food, it increases in length. The player's aim is to
make the snake as long as possible without causing it to collide with the game board's
boundaries or itself.
3. Action Plan
4. Resources required
7. Source code
<!DOCTYPE html>
<html>
<head>
<title>Snake Game</title>
<style> canvas {
border: 1px solid #000;
display: block;
margin: 0 auto;
}
</style>
</head>
<body>
<canvas id="gameCanvas" width="400" height="400"></canvas>
<p>Score: <span id="score">0</span></p>
<script>
const canvas = document.getElementById("gameCanvas");
const ctx = canvas.getContext("2d");
function drawSnake()
{ snake.forEach((segment) =>
{ ctx.fillStyle = "#000";
ctx.fillRect(segment.x, segment.y, gridSize, gridSize);
});
}
function drawFood()
{ ctx.fillStyle = "#f00";
ctx.fillRect(food.x, food.y, gridSize, gridSize);
}
function update() {
const head = { x: snake[0].x + dx, y: snake[0].y + dy };
function drawGame() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
drawSnake();
drawFood();
}
food = { x, y };
}
function gameOver() {
alert("Game Over! Your Score: " + score);
snake = [{ x: 10, y: 10 }];
score = 0;
document.getElementById("score").innerText = score;
dx = 0;
dy = gridSize;
}
function changeDirection(event) {
const keyPressed = event.key;
switch (keyPressed) { case
"ArrowUp": if (dy === 0) {
dx = 0; dy = -gridSize;
} break;
case "ArrowDown":
if (dy === 0)
{ dx = 0;
dy = gridSize;
} break;
case "ArrowLeft":
if (dx === 0)
{ dx = -gridSize;
dy = 0; }
break; case
"ArrowRight": if
(dx === 0) { dx
= gridSize; dy =
0; } break;
}
}
document.addEventListener("keydown", changeDirection);
setInterval(update, 100);
8.output
9.conclusion
the classic snake game is not only a nostalgic and enjoyable pastime but also a great example of
how game development can be both entertaining and instructive.
Building a snake game in JavaScript provides hands-on experience in coding logic, user
interaction, and basic game mechanics, making it an ideal starting point for those looking to
delve into game development or programming in general.
It teaches fundamental programming concepts such as handling user input, managing game
state, and rendering graphics.
Through this simple game, you can gain valuable experience and build a foundation for more
complex game development in the future.
ANNEXURE II
Evolution Sheet for the Micro
Project