Skip to content

andavag/MVC-Applications

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 

Repository files navigation

MineField: Custom MVC Architecture Demo

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."

The Game: 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).

alt text

Technical Architecture

This project is built to demonstrate strict adherence to software design patterns. The code is separated into two distinct packages:

1. The Core Framework (mvc.*)

A generic framework that handles the base of a desktop application. It knows nothing about the game logic.

  • Observer Pattern: Implements Publisher and Subscriber interfaces to decouple data state from the UI.
  • Command Pattern: All user modifications are encapsulated in Command objects, allowing for modular execution and potential undo/redo capabilities.
  • Abstract Factory Pattern: The AppFactory interface allows the framework to build the application without knowing the concrete classes.
  • Safe UI: Includes a SafeFrame and state management to prevent data loss (checking for "unsaved changes" on exit).

2. The Implementation (field.*)

The game logic that plugs into the framework.

  • Model: MineField manages the grid state, player location, and mine logic.
  • View: FieldView renders the grid dynamically using Java 2D graphics.
  • Factory: FieldFactory wires the specific game components into the generic framework.

Getting Started

Prerequisites

  • Java Development Kit (JDK) 8 or higher.

Installation & Execution

  1. Clone the repository

    git clone [https://github.com/yourusername/minefield-mvc.git](https://github.com/yourusername/minefield-mvc.git)
    cd minefield-mvc
  2. Compile the source code

    mkdir -p bin
    javac -d bin src/mvc/*.java src/field/*.java
  3. Run the Game

    java -cp bin field.FieldPanel

Project Structure

/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.

About

A lightweight, custom implementation of the Model-View-Controller (MVC) architectural pattern, designed to demonstrate core software design principles.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages