Skip to content

Latest commit

ย 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŽฎ Maze Adventure - Java Swing Game

A stunning, interactive maze game built with Java Swing featuring beautiful UI, database integration, enemy AI, and multiple game mechanics.

โœจ Features

๐ŸŽจ Beautiful UI

  • 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

๐ŸŽฏ Gameplay

  • 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

๐Ÿค– Enemy AI

  • 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

๐Ÿ’พ Database Integration

  • MySQL integration for user accounts
  • User registration and login system
  • Score tracking and statistics
  • Persistent leaderboard
  • Games played counter

๐ŸŽฎ Game Controls

  • WASD / Arrow Keys: Move player
  • R: Generate new maze
  • ESC: Pause menu (Resume/Main Menu/Logout)

๐Ÿ“‹ Requirements

Software

  • Java 11 or higher
  • MySQL Server 5.7+
  • MySQL JDBC Driver

Java Packages (All included in standard Java library)

  • javax.swing.* - GUI components
  • java.awt.* - Graphics rendering
  • java.sql.* - Database connectivity
  • java.util.* - Data structures

๐Ÿš€ Installation

1. Clone the Repository

git clone https://github.com/abdul-qudoos400/maze-adventure.git
cd maze-adventure

2. Set Up Database

Create 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);

3. Update Database Credentials

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!

4. Compile

javac Game.java
javac Maze.java
javac GameLogic.java

5. Run

java Game

๐Ÿ“ Project Structure

maze-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)

๐ŸŽฎ How to Play

Login/Registration

  1. Enter your username
  2. Click LOGIN if you have an existing account
  3. Click REGISTER to create a new account

Main Menu

  • START GAME - Begin a new maze game
  • LEADERBOARD - View top players and scores
  • LOGOUT - Return to login screen

During Gameplay

  1. Use WASD or Arrow Keys to move
  2. Collect the key visible on the maze
  3. Unlock the door at the exit (only possible with the key)
  4. Avoid enemies - they patrol the maze
  5. Avoid traps - you have 3 lives
  6. Collect treasures - earn bonus points
  7. Reach the exit with the key to win!

Press ESC to open the pause menu.

๐ŸŽจ Maze Generation Algorithm

Uses Depth-First Search (DFS) backtracking:

  1. Start at top-left (0,0)
  2. Mark as visited
  3. Randomly choose unvisited neighbors
  4. Carve walls between current and next cell
  5. Move to next cell
  6. When stuck, backtrack
  7. Continue until all cells visited

Result: A perfect maze with exactly one solution path!

๐Ÿค– Enemy AI Algorithm

Uses Breadth-First Search (BFS) pathfinding:

  1. Find shortest path from enemy to player
  2. 75% chance: Move along optimal path
  3. 15% chance: Take suboptimal but valid path
  4. 10% chance: Take worst available move
  5. If stuck in small area for 3+ moves, increase randomness

Creates challenging but fair gameplay!

๐Ÿ“Š Database Schema

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
);

๐Ÿ› Troubleshooting

"Database connection failed"

  • Ensure MySQL is running: mysql -u root -p
  • Check credentials in Connectivity class
  • Verify database 'project3' exists
  • See DATABASE_SETUP.md for detailed instructions

"Cannot find images"

  • Place image files in the same directory as .class files
  • Alternatively, update file paths in code

"Driver not found"

Game window appears blank

  • Ensure your screen resolution is at least 1024x768
  • Try resizing the window

๐Ÿ‘จโ€๐Ÿ’ป Author

Abdul Qudoos

๐Ÿ“ License

This project is open source and available under the MIT License.

๐ŸŽ“ Learning Resources

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

๐Ÿค Contributing

Feel free to fork and submit pull requests for any improvements!

Possible 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

โญ Show Your Support

If you like this project, please give it a star! โญ


Enjoy the game! ๐ŸŽฎ๐ŸŽ‰

About

Java-based pathfinding game showcasing Data Structures & Algorithms. Features: DFS procedural maze generation, BFS enemy AI with difficulty scaling (Easy/Medium/Hard), MySQL database integration via JDBC, persistent user management & leaderboards, custom Swing UI components with particle effects, sprite animations & professional styling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages