Minesweeper-Game

Minesweeper Game

A classic Minesweeper game with both Swing and JavaFX implementations, featuring clean architecture, comprehensive testing, and modern Java development practices.

Java Maven License


Features


Table of Contents


Prerequisites


Quick Start

# Clone the repository
git clone https://github.com/UNC-GDSC/Minesweeper-Game.git
cd Minesweeper-Game

# Build the project
mvn clean package

# Run the JavaFX version
mvn javafx:run

# Or run the Swing version
java -jar target/minesweeper-swing.jar

Project Structure

Minesweeper-Game/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ main/
โ”‚   โ”‚   โ”œโ”€โ”€ java/com/unc/gdsc/minesweeper/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ core/              # Core game logic (UI-independent)
โ”‚   โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Cell.java      # Cell model
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ GameBoard.java # Game board logic
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ swing/             # Swing implementation
โ”‚   โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ MinesweeperSwing.java
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ javafx/            # JavaFX implementation
โ”‚   โ”‚   โ”‚       โ”œโ”€โ”€ MinesweeperFXApp.java
โ”‚   โ”‚   โ”‚       โ””โ”€โ”€ StatusBarFX.java
โ”‚   โ”‚   โ””โ”€โ”€ resources/
โ”‚   โ”‚       โ””โ”€โ”€ styles.css         # JavaFX CSS styling
โ”‚   โ””โ”€โ”€ test/
โ”‚       โ””โ”€โ”€ java/com/unc/gdsc/minesweeper/core/
โ”‚           โ”œโ”€โ”€ CellTest.java      # Cell unit tests
โ”‚           โ””โ”€โ”€ GameBoardTest.java # GameBoard unit tests
โ”œโ”€โ”€ pom.xml                        # Maven configuration
โ”œโ”€โ”€ .gitignore                     # Git ignore rules
โ”œโ”€โ”€ LICENSE                        # MIT License
โ”œโ”€โ”€ README.md                      # This file
โ””โ”€โ”€ CONTRIBUTING.md                # Contribution guidelines


Building the Project

Using Maven

# Clean and compile
mvn clean compile

# Run tests
mvn test

# Package as JAR files
mvn package

# Generate JavaDoc
mvn javadoc:javadoc

Build Artifacts

After running mvn package, youโ€™ll find:


Running the Game

# Using Maven plugin
mvn javafx:run

# Or using the JAR file
java -jar target/minesweeper-javafx.jar

Features:

Swing Version

# Using Maven exec plugin
mvn exec:java -P swing

# Or using the JAR file
java -jar target/minesweeper-swing.jar

Features:


Testing

Run the complete test suite:

mvn test

Run specific test class:

mvn test -Dtest=CellTest
mvn test -Dtest=GameBoardTest

Generate test coverage report (requires Jacoco plugin):

mvn jacoco:report

How to Play

  1. Start the Game: Launch either the Swing or JavaFX version
  2. Reveal Cells: Left-click on a cell to reveal it
    • Numbers indicate how many mines are adjacent
    • Empty cells (no adjacent mines) auto-reveal neighbors
    • Mines end the game!
  3. Flag Mines: Right-click to mark suspected mine locations
  4. Win Condition: Reveal all non-mine cells
  5. New Game: Use the Game menu or dialog prompt to start over

Game Configuration

Both implementations use these default settings:

To customize, modify the constants in the respective main classes:

private static final int ROWS = 16;
private static final int COLS = 16;
private static final int MINES = 40;

Development

Code Organization

Design Patterns

Adding New Features

  1. For game logic changes, modify the core package
  2. For UI changes, modify the respective swing or javafx package
  3. Always add corresponding unit tests
  4. Update JavaDoc documentation

Maven Profiles

The project includes two Maven profiles:

# Run JavaFX version (default)
mvn exec:java -P javafx

# Run Swing version
mvn exec:java -P swing

Generating Documentation

Generate JavaDoc documentation:

mvn javadoc:javadoc

Documentation will be available in target/site/apidocs/index.html


Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

Quick Contribution Steps

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Commit with descriptive messages (git commit -m 'Add amazing feature')
  5. Push to your fork (git push origin feature/amazing-feature)
  6. Open a Pull Request

Architecture Highlights

Separation of Concerns

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     UI Layer (Swing/JavaFX)         โ”‚
โ”‚  - Event handling                   โ”‚
โ”‚  - Rendering                        โ”‚
โ”‚  - User interaction                 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚
               โ”‚ calls methods on
               โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚     Core Layer (Game Logic)         โ”‚
โ”‚  - Cell management                  โ”‚
โ”‚  - Mine placement                   โ”‚
โ”‚  - Win/loss detection               โ”‚
โ”‚  - Flood-fill algorithm             โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Benefits


Troubleshooting

JavaFX Not Found

If you encounter JavaFX module errors:

# Ensure you're using Java 11+
java -version

# Use Maven to run (handles modules automatically)
mvn javafx:run

Build Failures

# Clean Maven cache
mvn clean

# Delete target directory
rm -rf target/

# Rebuild
mvn install

Roadmap


Credits

Developed by: UNC-CH Google Developer Student Club License: MIT License Year: 2025


License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License

Copyright (c) 2025 UNC-CH Google Developer Student Club

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction...

Contact & Support


Happy Mining! ๐Ÿ’ฃ