A reusable Java Swing Framework & Strategy Game Implementation
This repository demonstrates a custom implementation of the Model-View-Controller (MVC) architectural pattern. It features a core framework package (mvc) designed for reusability, and a concrete implementation (field)—a grid-based navigation game called "MineField."
MineField is a strategy game where the player must navigate a 20x20 grid to reach the goal without stepping on hidden mines.
- Goal: Move from the top-left (0,0) to the bottom-right (19,19).
- Gameplay: As you move, squares reveal the number of adjacent mines (similar to Minesweeper).
- Controls: Navigate using cardinal and ordinal directions (N, S, E, W, NE, NW, SE, SW).
This project is built to demonstrate strict adherence to software design patterns. The code is separated into two distinct packages:
A generic framework that handles the base of a desktop application. It knows nothing about the game logic.
- Observer Pattern: Implements
PublisherandSubscriberinterfaces to decouple data state from the UI. - Command Pattern: All user modifications are encapsulated in
Commandobjects, allowing for modular execution and potential undo/redo capabilities. - Abstract Factory Pattern: The
AppFactoryinterface allows the framework to build the application without knowing the concrete classes. - Safe UI: Includes a
SafeFrameand state management to prevent data loss (checking for "unsaved changes" on exit).
The game logic that plugs into the framework.
- Model:
MineFieldmanages the grid state, player location, and mine logic. - View:
FieldViewrenders the grid dynamically using Java 2D graphics. - Factory:
FieldFactorywires the specific game components into the generic framework.
- Java Development Kit (JDK) 8 or higher.
-
Clone the repository
git clone [https://github.com/yourusername/minefield-mvc.git](https://github.com/yourusername/minefield-mvc.git) cd minefield-mvc -
Compile the source code
mkdir -p bin javac -d bin src/mvc/*.java src/field/*.java
-
Run the Game
java -cp bin field.FieldPanel
/MineField
/mvc # THE FRAMEWORK (Reusable)
├── AppFactory.java # Interface for config
├── AppPanel.java # Main Controller & Container
├── Command.java # Abstract Command
├── Model.java # Base data class (Publisher)
├── View.java # Base UI class (Subscriber)
└── ...
/field # THE GAME (Implementation)
├── FieldFactory.java # Configures the app as "MineField"
├── FieldPanel.java # Main Entry Point
├── MineField.java # Game Logic & Grid State
├── FieldView.java # Graphics Rendering
└── ...# MVC-Applications
A lightweight, custom implementation of the Model-View-Controller (MVC) architectural pattern, designed to demonstrate core software design principles.
