A stunning, interactive maze game built with Java Swing featuring beautiful UI, database integration, enemy AI, and multiple game mechanics.
- Animated login screen with particle effects
- Glowing buttons with hover animations
- 3D depth effects and smooth transitions
- Main menu with floating hexagonal orbs
- Dynamic gradient backgrounds
- Leaderboard with twinkling stars
- Procedurally generated mazes using DFS (Depth-First Search) algorithm
- Player movement with 4-directional controls (WASD or Arrow Keys)
- Intelligent enemy AI with pathfinding (BFS)
- Multiple game mechanics:
- Keys: Collect keys to unlock the exit
- Traps: Avoid hazards or lose lives
- Treasures: Find hidden treasures for bonus points
- Lives system (3 lives per game)
- Score tracking and leaderboard
- Uses BFS (Breadth-First Search) pathfinding to track player
- Anti-stuck mechanism to detect and escape dead ends
- Weighted decision-making for challenging but fair gameplay
- Sprite rotation to face movement direction
- MySQL integration for user accounts
- User registration and login system
- Score tracking and statistics
- Persistent leaderboard
- Games played counter
- WASD / Arrow Keys: Move player
- R: Generate new maze
- ESC: Pause menu (Resume/Main Menu/Logout)
- Java 11 or higher
- MySQL Server 5.7+
- MySQL JDBC Driver
javax.swing.*- GUI componentsjava.awt.*- Graphics renderingjava.sql.*- Database connectivityjava.util.*- Data structures
git clone https://github.com/abdul-qudoos400/maze-adventure.git
cd maze-adventureCreate MySQL database:
CREATE DATABASE IF NOT EXISTS project3;
USE project3;
CREATE TABLE IF NOT EXISTS game (
user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user VARCHAR(50) NOT NULL UNIQUE,
scores INT DEFAULT 0,
number_of_games_played INT DEFAULT 0
);
-- Insert test data (optional)
INSERT INTO game (user, scores, number_of_games_played) VALUES
('yusra', 0, 0),
('mama', 0, 0),
('sadia', 0, 0);Edit Game.java and update the Connectivity class:
private static final String URL = "jdbc:mysql://localhost:3306/project3";
private static final String USER = "root";
private static final String PASSWORD = "your_password"; // Change this!javac Game.java
javac Maze.java
javac GameLogic.javajava Gamemaze-adventure/
โโโ Game.java # Main entry point, enhanced UI, database integration
โโโ Maze.java # Original maze implementation and login system
โโโ GameLogic.java # Game level logic
โโโ DATABASE_SETUP.md # Database setup guide
โโโ project3.sql # Database dump
โโโ Images/
โ โโโ player_idel.png # Player standing sprite
โ โโโ player_move1.png # Player walking frame 1
โ โโโ player_move2.png # Player walking frame 2
โ โโโ enemy.png # Enemy sprite
โ โโโ key2.png # Key collectible
โ โโโ door.png # Exit door
โ โโโ trap.png # Hazard sprite
โ โโโ treasure.png # Treasure sprite
โ โโโ yusra1.jpeg # Login background
โ โโโ yusra2.jpeg # Menu background
โโโ Compiled Classes (auto-generated)
- Enter your username
- Click LOGIN if you have an existing account
- Click REGISTER to create a new account
- START GAME - Begin a new maze game
- LEADERBOARD - View top players and scores
- LOGOUT - Return to login screen
- Use WASD or Arrow Keys to move
- Collect the key visible on the maze
- Unlock the door at the exit (only possible with the key)
- Avoid enemies - they patrol the maze
- Avoid traps - you have 3 lives
- Collect treasures - earn bonus points
- Reach the exit with the key to win!
Press ESC to open the pause menu.
Uses Depth-First Search (DFS) backtracking:
- Start at top-left (0,0)
- Mark as visited
- Randomly choose unvisited neighbors
- Carve walls between current and next cell
- Move to next cell
- When stuck, backtrack
- Continue until all cells visited
Result: A perfect maze with exactly one solution path!
Uses Breadth-First Search (BFS) pathfinding:
- Find shortest path from enemy to player
- 75% chance: Move along optimal path
- 15% chance: Take suboptimal but valid path
- 10% chance: Take worst available move
- If stuck in small area for 3+ moves, increase randomness
Creates challenging but fair gameplay!
CREATE TABLE game (
user_id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
user VARCHAR(50) NOT NULL UNIQUE,
scores INT DEFAULT 0,
number_of_games_played INT DEFAULT 0
);- Ensure MySQL is running:
mysql -u root -p - Check credentials in Connectivity class
- Verify database 'project3' exists
- See DATABASE_SETUP.md for detailed instructions
- Place image files in the same directory as .class files
- Alternatively, update file paths in code
- Download MySQL JDBC driver from: https://dev.mysql.com/downloads/connector/j/
- Add to Java classpath
- Ensure your screen resolution is at least 1024x768
- Try resizing the window
Abdul Qudoos
- GitHub: @abdul-qudoos400
This project is open source and available under the MIT License.
This project demonstrates:
- Object-Oriented Programming (OOP) in Java
- GUI Development with Swing
- Database connectivity with JDBC
- Pathfinding algorithms (BFS, DFS)
- Game loop and animation
- Collision detection
- State management
- Event handling
Feel free to fork and submit pull requests for any improvements!
- Difficulty levels (easy, medium, hard)
- Power-ups system
- Sound effects and background music
- Multiple enemy types
- Time-based challenges
- Bonus levels
- Achievements system
- Mobile version
If you like this project, please give it a star! โญ
Enjoy the game! ๐ฎ๐