Snake Game

This is a simple Snake Game implemented in Java using Swing for the graphical user interface. The game allows the player to control a snake that moves around the game board, eating food and growing longer. The game ends when the snake collides with itself or the boundaries of the game board.

Features

  • Snake grows longer each time it eats food.
  • Game over when the snake collides with itself or the boundaries of the game board.
  • Score is displayed on the screen.
  • Player can control the snake's direction using arrow keys.

How to Run

  1. Ensure you have Java Development Kit (JDK) installed on your system.
  2. Compile the source code files (Game.java) using javac command:
  3. Run the compiled program using java command:
  4. The game window will open, and you can start playing by using the arrow keys to control the snake's direction.

Controls

  • Use the up, down, left, and right arrow keys to control the snake's movement.
  • Press any other key to pause or resume the game.

Game Mechanics

  • The snake starts with a single segment.
  • The snake moves continuously in the direction it is facing.
  • The player must maneuver the snake to eat food items that appear randomly on the board.
  • Each time the snake eats food, it grows longer by one segment.
  • The game ends if the snake collides with itself or hits the boundaries of the game board.
  • The score is displayed on the screen, representing the length of the snake.

Output

Game Start

Game-Start

Game Over

Game over

Files

  • Game.java: Contains the main game logic, including the game board, snake movement, collision detection, and scoring.

Requirements

  • Java Development Kit (JDK) installed on your system.

Credits

This game was implemented by Paaras Sharma.

Enjoy playing the Snake Game!