https://github.com/samyam81/snakejava
Snake.The game features a snake that moves around the screen, eating apples to grow longer. The player controls the snake's direction using arrow keys. The game ends if the snake collides with itself or the screen boundaries.
https://github.com/samyam81/snakejava
java snake snake-game
Last synced: 9 months ago
JSON representation
Snake.The game features a snake that moves around the screen, eating apples to grow longer. The player controls the snake's direction using arrow keys. The game ends if the snake collides with itself or the screen boundaries.
- Host: GitHub
- URL: https://github.com/samyam81/snakejava
- Owner: samyam81
- License: mit
- Created: 2024-02-16T08:33:46.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-06-01T06:45:00.000Z (about 2 years ago)
- Last Synced: 2025-06-04T22:28:21.945Z (about 1 year ago)
- Topics: java, snake, snake-game
- Language: Java
- Homepage:
- Size: 17.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Snake Game
This Java program implements a classic Snake game using Swing. The game features a snake that moves around the screen, eating apples to grow longer. The player controls the snake's direction using arrow keys. The game ends if the snake collides with itself or the screen boundaries.
## Features
- Snake grows longer when it eats an apple.
- Score displayed on the screen.
- Game over screen displayed when the snake collides with itself or the screen boundaries.
## Components
- **GameFrame:** Extends JFrame to create the game window. It adds a GamePanel to the frame and sets up various properties such as title, size, and location.
- **GamePanel:** Extends JPanel and implements the game logic. It handles painting the game elements, moving the snake, checking collisions, and processing user input using KeyAdapter.
- **SnakeGame:** Main class to start the game by creating an instance of GameFrame.
## How to Play
1. Use the arrow keys to control the direction of the snake.
2. Guide the snake to eat apples and grow longer.
3. Avoid collisions with the snake's body or the screen boundaries.
4. The game ends when the snake collides, and the final score is displayed.
Enjoy playing the classic Snake game!