Skip to content

Yagnesh-R/SNAKE-GAME

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SNAKE-GAME

Welcome to the Snake Game project! This is a classic implementation of the Snake game using HTML, CSS, and JavaScript. In this game, players control a snake that grows longer as it eats food, while avoiding collisions with the walls and its own body. Take a trip down memory lane and enjoy hours of entertainment as you control the snake and try to eat as much food as possible, all while avoiding collisions with the walls and yourself. Unleash nostalgia and challenge your reflexes with a captivating Snake Game masterpiece. Crafted using the synergy of Javascript's logic, HTML's structure, and CSS's style, embark on a pixelated adventure of growth and strategy. Old-school fun meets modern tech!

Table of Contents :

  • Prerequisites
  • How to Play
  • Game Mechanics
  • Game Logic Overview
  • Customization
  • Acknowledgments

Prerequisites

Before you begin, ensure you have the following software installed on your computer:

  • A modern web browser (e.g., Google Chrome, Mozilla Firefox)
  • A text editor or integrated development environment (IDE) for code editing!

How to Play

  1. Getting Started: Open the index.html file in a modern web browser to start the game.

  2. Controls: Use the arrow keys (up, down, left, and right) on your keyboard to control the snake's direction. The snake will continue moving in the chosen direction until you change it.

  3. Objective: Your objective is to eat the food that appears on the screen. Each time the snake eats a piece of food, it grows longer.

  4. Game Over: The game ends if the snake collides with the walls of the game area or if it collides with itself. Try to achieve the highest possible score by eating as much food as you can without crashing!

Game Mechanics

This Snake Game is implemented using HTML, CSS, and JavaScript. The main components of the game include:

  • index.html: This file contains the structure of the game, including the game board and necessary elements.

  • style.css: This file contains the styling for the game, including the appearance of the snake, food, and game board.

  • script.js: This file contains the game logic written in JavaScript. It handles the movement of the snake, generating food, detecting collisions, and updating the game state.

Game Logic Overview

The game is implemented using HTML5 Canvas for rendering graphics and JavaScript for game logic.

  • The snake's movement and direction are controlled by capturing arrow key events.
  • The snake's body is represented as an array of linked segments. As the snake eats food, new segments are added to the array.
  • Food is placed randomly on the game grid, and the snake grows longer each time it consumes food.
  • Collision detection is used to check for collisions with walls and the snake's body.
  • When the game ends, the player's score is displayed, and they have the option to restart the game.

Customization

Feel free to customize and enhance the game as you like! Here are a few ideas:

  • Game Design: Modify the CSS styles in the 'style.css' file to change the appearance of the game, such as colors, fonts, and layout.

  • Difficulty Levels: Adjust the speed of the snake's movement to create different difficulty levels. You can modify the speed variable in the 'script.js' file.

  • Grid Size: Experiment with different grid sizes by changing the 'gridSize' variable in the 'script.js' file. This can affect the overall layout and difficulty of the game.

Experiment with different colors and visual elements to give the game a unique look.

Acknowledgments

This Snake Game was created as a learning exercise and is inspired by the classic Snake game that has been enjoyed by generations. It was built as a project to learn and demonstrate the usage of HTML, CSS, and JavaScript for game development.

Special thanks to the online coding communities, tutorials, and resources that contributed to the development of this project.

If you have any questions or suggestions, feel free to reach out to the project's author: [email protected]

Enjoy the game! 🐍🎮