0% found this document useful (0 votes)
16 views11 pages

HTML Snake Game Project Report

sample project
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views11 pages

HTML Snake Game Project Report

sample project
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

KHWOPA SECONDARY SCHOOL

DEPARTMENT OF COMPUTER SCIENCE


Dekocha-06,BHAKTAPUR

FINAL REPORT
ON
"SNAKE GAME USING HTML"
A Report Submitted for the partial fulfillment of requirement for the degree of NEB
in computer science

Submitted To:
Submitted Department of Computer
by:
Science
Khwopa Secondary School
John Prajapati Dekocha-06, Bhaktapur
(413)
Nayan Thapa
UNDER THE GUIDANCE OF
(422)
…………………………….

Date of submission: 2080/ /


DEPARTMENT OF COMPUTER SCIENCE
KHWOPA SECONDARY SCHOOL
DEKOCHA-06, BHAKTAPUR

CERITFICATE
This is to certify that the project entitled “Programming with HTML”
submitted by Mr. Samir Dulal, Mr. Rojan Koju , Mr. Nayan Thapa
& Mr. John Prajapati in a partial fulfillment of the requirements for the
internal marks of Computer science in NEB (Nepal Education Board)
Class 11 (XI), is a bonafide work to the best of my/our knowledge and
may be placed before the examination board for their consideration.
Panel of Examiners:
Name Signature Date
External

Examiner

…………………

Project Supervisors
ACKNOWLEDGEMENT
We are thankful to all those who have helped us directly or indirectly
with this project. Foremost, we would like to thank the Department of
Computer Science of Khwopa Secondary School for the giving an
opportunity to carry out project entitled
"PC based Snake Game".
We would like to thank our computer teacher Er. Pujan Changubhari for
their guidance while developing project and also for organizing the
project schedules. Also we would like to acknowledge their effort that
encouraged us to take this challenging project. We would also like to
thanks our brother Amit Achara to helping for developing the project.
We would also like to offer our gratitude towards some of our friends
who helped throughout our project development phase by providing
several references regarding different links for code and making project
report.
ABSTRACT
This is our project related with one of the famous "snake game". Now a
day, most of the people in this world loves to play video games. To
provide a video game for them we create our new HTML project
“Snake Game”. In this game you will enjoy. You will get task eat apple
there from you can enjoy. If you touch the border of given certain area
and the body of the snake by its head you will be out from this game
you have to click start play game again. The main objective of this
project is to provide the enjoyment in which we can get by playing
video game.
Table of Contents
INTRODUCTION.................................................................................................................................6
BACKGROUND.........................................................................................................................................6
OBJECTIVES..............................................................................................................................................6
APPLICATIONS.........................................................................................................................................7
SCOPE AND LIMITATIONS........................................................................................................................8
INTRODUCTION
BACKGROUND
Technology is rapidly increasing in today’s world. Internet is one of the rapidly
increasing technologies. The use and user are increasing day by day. Nowadays,
people are using internet for communication, collaboration, and many others
things that done online. With the development of internet, computer
programming is also developed rapidly in the modern era. Computer
Programming is the fundamental skills for so many different applications, not
just software development or cutting-edge research into artificial intelligence.
Through the help of computer programming we can do research and
development, government operations, web development and designs, marketing
and business operations, data science and artificial intelligence, cyber security
etc.

In the world of programming, we have visualized a small project based on


HTML programming code and we have designed a simple PC based snake game.
Getting the theoretical knowledge from the classroom, we designed a simple
demonstration of the use of canvas, strip, and function in the program.

OBJECTIVES

Too familiar with the use of HTML programming in realistic manner.


To learn how to use canvas, stript , function in the program.
To be able to design a simple application by use of HTML codes.

APPLICATIONS

To show how the code really works .


To provide general knowledge about HTML programming.
To demonstrate that how coding is important in modern era.
SCOPE AND LIMITATIONS

The first and foremost things are our country is lacking on the development of
internet and skilled programmers. So the scope of our project is to make
everyone an eligible programmer and able to design software, applications in our
own country.
The limitations are people don’t have computers in their home to practice
programming and familiarized with it.
Methodology

Code for the game


We have used the following codes to create our website.
 HTML Structure:

 `<!DOCTYPE html>`: Declares the document type and version of


HTML being used.
 `<html lang="en">`: Specifies the document's language.
 `<head>`: Contains metadata, including the character set and the title of
the page.
 `<center>`: Deprecated HTML tag used to center content. It's generally
recommended to use CSS for centering.
 `<body bgcolor="black">`: Sets the background color of the body to
black.
 `<canvas id="game_field" width="600px" height="600px"
style="border: 10px solid brown">`: Creates an HTML5 canvas element
with an ID of "game_field," width and height of 600 pixels each, and a
brown border.

 JavaScript:
- Immediately Invoked Function Expression (IIFE): Wraps the entire JavaScript
code within a function that is immediately invoked. This is a common pattern to
avoid polluting the global namespace.
 Constants and Variables:
¤ `CELLS_COUNT`: Defines the number of cells in each
row/column of the game grid.
¤ `CELL_SIZE`: Calculates the size of each cell based on the
canvas width and the number of cells.
¤ `snake`: An array to store the positions of the snake's segments.
¤ `food`: An object representing the position of the food on the
canvas.
¤ `dir`: Keeps track of the current direction the snake is moving.
¤ `score`: Tracks the player's score.
¤ `speedCoeff`: A coefficient affecting the speed of the snake.

 Colors:
¤ `FIELD_COLOR`, `FOOD_COLOR`, `GRID_COLOR`,
`SNAKE_COLOR`: Constants representing colors used in the game.

 Event Listener:
¤ Listens for key down events to change the direction of the snake
based on arrow key presses.

 Drawing Functions:
¤ `draw_field()`: Draws the game field, including the background
and grid.
¤ `draw_food()`: Draws the food on the canvas.
¤ `draw_snake()`: Draws the snake on the canvas.

 Initialization and Game Logic:


¤ `init()`: Initializes the game state, setting up the snake, direction,
score, and spawning the initial food.
¤ `isContact(fieldObj)`: Checks if a given position (food or snake)
is in contact with the snake.
¤ `isValid(pos)`: Checks if a given position is within the boundaries
of the canvas.
¤ `spawn_food()`: Randomly places food on the canvas, ensuring it
does not overlap with the snake and is a valid position.
¤ `step()`: Handles the main game logic, including snake
movement, collision detection, scoring, and updating the canvas.
The function is recursively called with a timeout to create the
game loop.

 Initialization and Game Start:


¤ `init()` is called to set up the initial game state.
¤ `step()` is called to start the game loop.
Block Diagram
Gamers Snake Game
Event handling

Keyboard events (key down)

Change direction (dir)

Game loop

Draw function (draw field,


draw snake, draw food)

Initialization (init)

Spawn food (food)

Movement and collision


detection(step)

Game over check

Common questions

Powered by AI

The rapid development of the internet has propelled the evolution of computer programming by expanding its applications beyond traditional software development to include web development, AI research, and more. The Snake Game initiative taps into this evolution by using HTML and JavaScript, languages crucial for modern web development. The project exemplifies how programming education can bridge the gap between theoretical knowledge and real-world application, showcasing the importance of programming skills in the digital era .

A project like the Snake Game provides educational benefits beyond traditional programming instruction by fostering creativity, enhancing problem-solving skills, and encouraging innovation. Students engage in the end-to-end process of game development which includes design, coding, testing, and iteration. This hands-on experience helps in understanding the software development lifecycle, encouraging teamwork and communication when done collaboratively, and motivating self-directed learning and critical thinking—skills vital in any career path .

Demonstrating programming concepts through game development, as seen in the Snake Game project, is educationally significant because it provides a fun and interactive platform for engaging students. Game development inherently requires applying multiple programming concepts such as algorithms, data structures, event handling, and graphics, offering comprehensive learning opportunities. This approach helps students visualize abstract concepts, making the learning experience more relatable and enjoyable, thus enhancing retention and understanding of programming fundamentals .

The Snake Game project provides a practical demonstration of HTML programming by utilizing canvas, script, and functions to create a simple game application. This project familiarizes students with the foundational aspects of HTML and JavaScript, enhancing their understanding of how these languages work in real-world applications. By creating the game, students learn the usage and interaction of HTML structures like `<DOCTYPE>`, `<canvas>`, and JavaScript functions such as IIFE for better coding practices .

The project integrates theoretical knowledge into practical application by transferring classroom learning about HTML and JavaScript into the creation of a snake game, a tangible and interactive program. This integration is significant because it bridges the gap between learning concepts and applying them, promoting active learning and enhancing students' understanding of programming. By crafting a functional game, students deepen their comprehension through real-world application, a critical educational approach for developing problem-solving and technical skills .

The authors utilize JavaScript functions to manage game operations like movement and collision detection by implementing an event listener to change snake direction based on arrow key inputs and using a game loop function (`step()`) to handle movement logic and boundary checking. The collision detection is done through validation functions like `isValid(pos)` to ensure the snake remains within bounds and `isContact(fieldObj)` to detect when the snake comes in contact with food or itself, ensuring game integrity and responsiveness .

Using deprecated HTML elements like `<center>` in modern web development is generally discouraged due to the shift towards CSS for styling and layout control. This project demonstrates a basic use of HTML, which may not align with best practices in current web design, where CSS is recommended for centering and other styling tasks. Therefore, while the project serves educational purposes, adopting modern coding practices by utilizing CSS would enhance its effectiveness and relevance in current developmental standards .

The main objectives of the Snake Game project are to familiarize students with HTML programming in a practical manner, teach them to use canvas, script, and function, and enable them to design a simple application using HTML codes. These objectives align with the current trends in computer science education, which emphasize hands-on, project-based learning to develop coding skills, an approach critical in a world where digital literacy is increasingly important .

The authors identify a lack of internet development and skilled programmers in Nepal as primary limitations, along with the lack of access to computers for practicing programming. These factors could hinder educational outcomes by limiting students' exposure to practical, hands-on experience, which is essential for effective learning in computer science. Addressing these limitations is crucial for enabling students to become proficient programmers and designers, capable of contributing to technological advancements .

The Snake Game project underscores the importance of coding by illustrating how programming skills enable the development of interactive applications and games, which are integral parts of modern technology usage. The project highlights the role of coding in creating platforms for entertainment and learning, demonstrating its imperative presence in fields like internet-based communications, AI, and other digital services, thereby emphasizing its broad applicability in today's tech-driven world .

You might also like