Name: Two Player Snake Game (Inspired by Snake.io) Technologies: Java (Core, AWT/Swing), MySQL, Griddle Developer: Haris Khan (GitHub: developebyharis/snake-game)
This project is a real-time, competitive snake game for two players. Unlike traditional implementations, this game integrates with a MySQL database (via Griddle) to store and retrieve persistent data such as scores, matches, and player history.
Two-player mode: Player 1 (W/A/S/D) vs Player 2 (arrow keys).
Database-driven scoreboard:
Collision detection for snake-to-snake, walls, and self-collision.
Intelligent food placement: Prevents spawning inside snakes or outside the grid.
Persistent session tracking: Results remain saved even after closing the game.
Handles game rendering, animations, and input capture.
Uses a game loop for smooth real-time movement.
UI displays:
MySQL database schema stores:
players (id, name, wins, losses, high_score)
matches (id, player1, player2, winner, date_played)
Griddle is used as the ORM/data access layer to connect Java with MySQL.
CRUD operations:
Snakes move in sync with player input.
Food spawns at random positions not occupied by snakes.
On collision:
Clone the repository:
git clone https://github.com/developebyharis/snake-game.git
The schema is build on MySql CLI.
Configure DB credentials in /build.gradle
.
Compile & run the project:
javac SnakeGame.java
java SnakeGame
Play and watch results sync with the MySQL-powered leaderboard.
Decision | Reason |
---|---|
Java AWT & Swing | Lightweight, portable GUI framework ideal for quick rendering. |
MySQL + Griddle | Adds persistence and realism by tracking game history & leaderboard. |
Two-player mode | Makes the game competitive and engaging. |