# andc101/dungeon-dash architecture

> Architecture diagram of the GitHub repository andc101/dungeon-dash, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andc101/dungeon-dash
- Repository: https://github.com/andc101/dungeon-dash

## Overview

##### Project Type and Purpose
- Dungeon-Dash is a Java-based platformer game with built-in level editing functionality.
- It employs Java GUI (likely Swing or AWT) for rendering game components.
- The game utilizes multithreading for game-loop management, file I/O for saving levels and high scores, as well as audio (using .wav files) and sprite-based graphics.

##### Analyzing the File Structure
- Top-Level Game Components:
- Main.java serves as the entry point.
- GameFrame.java and GamePanel.java handle the UI—GameFrame likely provides the main window, while GamePanel contains the rendering and game loop.
- Game Objects and Entities:
- Classes like Player.java, Goblin.java, Turret.java, Projectile.java, etc., represent various in-game objects and enemy logic.
- Other classes (e.g., Block.java, Stone.java, CrackedStone.java, Chest.java, Portal.java) represent environmental components or interactive objects.
- Level and Resource Management:
- Files such as LevelSave.txt, HighScores.txt, and names.txt are used for saving level configurations, high scores, or other game state data.
- The Images folder and the Music directory (with several audio files) handle the graphical and auditory aspects.
- Miscellaneous:
- Files such as Pair.java might be used for utility purposes (coordinates, pairs of data).
- The built-in level editor functionality implies additional user interaction where level data is read from or saved to disk.

- Game Engine / Loop: Represent multithreading where the game loop in GamePanel periodically updates game objects and handles collision detection.
- Game Entities: Group all the game “actors” (Player, Goblin, Turret, Projectile, Power-ups such as SpeedBoost and OneUp) into a single module; note that each entity encapsulates its logic and properties.
- Level Editor: Since the game includes a level editor, show a separate component for level creation, which interfaces with file I/O (LevelSave.txt and possibly names.txt) to store and load level data.
- Resource Manager: Include a module for “Resources” that handles external files (Images for sprites and Music files for sound effects).
- Data Persistence: A dedicated component managing file I/O for HighScores and level saves.

- Relationships and data flow:
- The “Main” component triggers initialization, which instantiates the UI (GameFrame and GamePanel).
- Within GamePanel, the game loop continuously updates and renders the game state, interacting with individual game entities.
- Entities trigger events (e.g., collision detection, power-ups) that update the game state and may invoke file I/O operations for saving scores or levels.
- The Level Editor interacts with Resources and Data Persistence components to load and save level information.

##### Architectural Patterns & Design Principles
- Modularity through distinct classes for each game component—this reflects solid OOP practices.
- Separation of Concerns: Rendering, game logic, and resource management are clearly decoupled.
- Multithreading is used to keep the UI responsive while the game loop processes independent events.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    subgraph "Entry Point"
        Main["Main"]:::entry
    end

    %% UI Layer
    subgraph "UI Layer"
        GameFrame["GameFrame"]:::ui
        GamePanel["GamePanel"]:::ui
    end

    %% Game Engine
    subgraph "Game Engine"
        GameLoop["Game Loop & Rendering"]:::engine
    end

    %% Game Entities
    subgraph "Game Entities"
        Player["Player"]:::entity
        Goblin["Goblin"]:::entity
        Turret["Turret"]:::entity
        Projectile["Projectile"]:::entity
        SpeedBoost["SpeedBoost"]:::entity
        OneUp["OneUp"]:::entity
    end

    %% Environment & Level Components
    subgraph "Environment & Level Components"
        Block["Block"]:::environment
        Stone["Stone"]:::environment
        CrackedStone["CrackedStone"]:::environment
        Chest["Chest"]:::environment
        Portal["Portal"]:::environment
        Ladder["Ladder"]:::environment
        Ice["Ice"]:::environment
        Background["Background"]:::environment
    end

    %% Level Editor
    subgraph "Level Editor"
        LevelEditor["Level Editor"]:::editor
    end

    %% Resource Manager
    subgraph "Resource Manager"
        Images["Images"]:::resource
        Music["Music"]:::resource
    end

    %% Data Persistence Cluster
    subgraph "Data Persistence"
        DDP["Data Persistence"]:::database
        LevelSave["LevelSave.txt"]:::database
        HighScores["HighScores.txt"]:::database
        Names["names.txt"]:::database
    end

    %% Utility Component
    subgraph "Utility"
        Pair["Pair"]:::utility
    end

    %% Relationships
    Main -->|"initializes"| GameFrame
    GameFrame -->|"embeds"| GamePanel
    GamePanel -->|"runs-game-loop"| GameLoop

    GameLoop -->|"updates"| Player
    GameLoop -->|"updates"| Goblin
    GameLoop -->|"updates"| Turret
    GameLoop -->|"updates"| Projectile
    GameLoop -->|"updates"| SpeedBoost
    GameLoop -->|"updates"| OneUp

    GameLoop -->|"renders"| Block
    GameLoop -->|"renders"| Stone
    GameLoop -->|"renders"| CrackedStone
    GameLoop -->|"renders"| Chest
    GameLoop -->|"renders"| Portal
    GameLoop -->|"renders"| Ladder
    GameLoop -->|"renders"| Ice
    GameLoop -->|"renders"| Background

    LevelEditor -->|"saves/loads-level-data"| DDP
    LevelEditor -->|"fetches-resources"| Images
    LevelEditor -->|"fetches-resources"| Music

    GameLoop -->|"uses-resources"| Images
    GameLoop -->|"uses-resources"| Music

    DDP ---|"stores-data"| LevelSave
    DDP ---|"stores-data"| HighScores
    DDP ---|"stores-data"| Names

    Player ---|"utilizes"| Pair
    Goblin ---|"utilizes"| Pair
    Turret ---|"utilizes"| Pair
    Projectile ---|"utilizes"| Pair
    Block ---|"utilizes"| Pair
    Stone ---|"utilizes"| Pair
    CrackedStone ---|"utilizes"| Pair
    Chest ---|"utilizes"| Pair
    Portal ---|"utilizes"| Pair
    Ladder ---|"utilizes"| Pair
    Ice ---|"utilizes"| Pair
    Background ---|"utilizes"| Pair

    %% Click Events
    click Main "https://github.com/andc101/dungeon-dash/blob/main/Main.java"
    click GameFrame "https://github.com/andc101/dungeon-dash/blob/main/GameFrame.java"
    click GamePanel "https://github.com/andc101/dungeon-dash/blob/main/GamePanel.java"
    click GameLoop "https://github.com/andc101/dungeon-dash/blob/main/GamePanel.java"
    click Player "https://github.com/andc101/dungeon-dash/blob/main/Player.java"
    click Goblin "https://github.com/andc101/dungeon-dash/blob/main/Goblin.java"
    click Turret "https://github.com/andc101/dungeon-dash/blob/main/Turret.java"
    click Projectile "https://github.com/andc101/dungeon-dash/blob/main/Projectile.java"
    click SpeedBoost "https://github.com/andc101/dungeon-dash/blob/main/SpeedBoost.java"
    click OneUp "https://github.com/andc101/dungeon-dash/blob/main/OneUp.java"
    click Block "https://github.com/andc101/dungeon-dash/blob/main/Block.java"
    click Stone "https://github.com/andc101/dungeon-dash/blob/main/Stone.java"
    click CrackedStone "https://github.com/andc101/dungeon-dash/blob/main/CrackedStone.java"
    click Chest "https://github.com/andc101/dungeon-dash/blob/main/Chest.java"
    click Portal "https://github.com/andc101/dungeon-dash/blob/main/Portal.java"
    click Ladder "https://github.com/andc101/dungeon-dash/blob/main/Ladder.java"
    click Ice "https://github.com/andc101/dungeon-dash/blob/main/Ice.java"
    click Background "https://github.com/andc101/dungeon-dash/blob/main/Background.java"
    click LevelSave "https://github.com/andc101/dungeon-dash/blob/main/LevelSave.txt"
    click HighScores "https://github.com/andc101/dungeon-dash/blob/main/HighScores.txt"
    click Names "https://github.com/andc101/dungeon-dash/blob/main/names.txt"
    click Images "https://github.com/andc101/dungeon-dash/tree/main/Images"
    click Music "https://github.com/andc101/dungeon-dash/tree/main/Music"
    click Pair "https://github.com/andc101/dungeon-dash/blob/main/Pair.java"

    %% Styles
    classDef entry fill:#f9f,stroke:#333,stroke-width:2px;
    classDef ui fill:#bbf,stroke:#333,stroke-width:2px;
    classDef engine fill:#ff9,stroke:#333,stroke-width:2px;
    classDef entity fill:#9f9,stroke:#333,stroke-width:2px;
    classDef environment fill:#fc9,stroke:#333,stroke-width:2px;
    classDef editor fill:#c9f,stroke:#333,stroke-width:2px;
    classDef resource fill:#9cf,stroke:#333,stroke-width:2px;
    classDef database fill:#fcc,stroke:#333,stroke-width:2px;
    classDef utility fill:#ccc,stroke:#333,stroke-width:2px;
```
