# ycchnn/final-project architecture

> Architecture diagram of the GitHub repository ycchnn/final-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-21). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ycchnn/final-project
- Repository: https://github.com/ycchnn/final-project

## Overview

##### Project Type and Purpose
- This is a single-executable C++ game (tower-defense style) using the Allegro graphics/audio library.

##### File Structure
- Top-level code: Main.cpp, Game.cpp/h, Level.cpp/h, UI.cpp/h, OperationCenter, DataCenter and other “Center” classes under `data/`.
- Assets: `assets/` contains subfolders for fonts, images, GIFs, sounds, and level text files.
- Support libraries: `algif5/` for GIF decoding.
- Build & config: makefile, Doxyfile.

##### Core Components
a. External Library
- Allegro5 (graphics, input, audio)
- algif5 (GIF decoding)
b. Application Entry Point
- Main (Main.cpp) → initializes Engine
c. Core Engine / Game Loop
- Game class (Game.cpp/h): init(), runLoop(), cleanup()
- Level class: encapsulates level data and progression
d. Resource Managers (“Centers”)
- DataCenter → orchestrates resource loading/unloading
- FontCenter, GIFCenter, ImageCenter, SoundCenter → wrap Allegro calls
- OperationCenter → input handling & event dispatch
e. Entities & Domain Objects
- Monsters (`monsters/`): Monster base and specific types
- Towers (`towers/`): Tower base, specialized towers, bullets
- Player, Object, UI classes
f. Assets Storage
- File-based assets under `assets/` (images, GIFs, sounds, levels)
g. Utilities
- algif5 library
- Utils.h for shared definitions

##### Relationships & Data Flows
- Main → Game.init()
- Game.init() → DataCenter.loadAll():
- FontCenter, GIFCenter, ImageCenter, SoundCenter read files from `assets/`
- Game.runLoop():
- OperationCenter polls Allegro events (keyboard, mouse)
- Input events → OperationCenter → Game/Level/Player
- Game.update() updates Level, Entities (monsters, towers)
- SoundCenter plays effects/music on events
- Level contains & manages Entities; Entities request assets from DataCenter
- On exit: Game.cleanup() → DataCenter.freeAll()

##### Architectural Patterns & Principles
- Manager/Center pattern: centralized resource management.
- Game Loop pattern.
- Component-based entities: base classes + specialized subclasses.
- Separation of concerns: rendering, input, audio, logic all in separate modules.

##### Final Checklist
- Initialization sequence
- Game loop data flows

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Libraries
    subgraph "External Libraries"
        Allegro5["Allegro5"]:::ext
        algif5["algif5"]:::ext
    end

    %% Core Application
    subgraph "Core Application"
        Main["Main"]:::core
        Game["Game"]:::core
        Level["Level"]:::core
        UI["UI"]:::core
    end

    %% Resource Managers
    subgraph "Resource Managers"
        DataCenter["DataCenter"]:::manager
        FontCenter["FontCenter"]:::manager
        GIFCenter["GIFCenter"]:::manager
        ImageCenter["ImageCenter"]:::manager
        SoundCenter["SoundCenter"]:::manager
        OperationCenter["OperationCenter"]:::manager
    end

    %% Entities
    subgraph "Entities"
        MonsterFamily["Monsters"]:::entity
        TowerFamily["Towers"]:::entity
        Bullet["Bullet"]:::entity
        Player["Player"]:::entity
        Object["Object"]:::entity
        Hero["Hero"]:::entity
        Sun["Sun"]:::entity
    end

    %% Utilities
    subgraph "Utilities"
        Shapes["Shapes"]:::util
        Utils["Utils"]:::util
    end

    %% Assets
    subgraph "Assets"
        Fonts["Fonts"]:::asset
        GIFs["GIFs"]:::asset
        Images["Images"]:::asset
        Sounds["Sounds"]:::asset
        Levels["Levels"]:::asset
    end

    %% Initialization Flow
    Main -->|"init()"| Game
    Game -->|"loadAll()"| DataCenter
    DataCenter --> FontCenter
    DataCenter --> GIFCenter
    DataCenter --> ImageCenter
    DataCenter --> SoundCenter
    FontCenter -->|"load font"| Fonts
    GIFCenter -->|"decode gif"| GIFs
    ImageCenter -->|"load image"| Images
    SoundCenter -->|"load sound"| Sounds

    %% Game Loop
    Game -->|"runLoop()"| OperationCenter
    OperationCenter -->|"pollEvent()"| Game
    OperationCenter -->|"dispatch()"| Player
    Game -->|"update()"| Level
    Level --> MonsterFamily
    Level --> TowerFamily

    %% Rendering & Audio
    Game -->|"render()"| MonsterFamily
    Game -->|"render()"| TowerFamily
    Game -->|"render()"| Player
    Game -->|"render()"| Bullet
    Game -->|"render()"| UI
    MonsterFamily --> ImageCenter
    TowerFamily --> ImageCenter
    Player --> ImageCenter
    Bullet --> ImageCenter
    UI --> FontCenter
    Game -->|"playSound()"| SoundCenter

    %% Cleanup
    Game -->|"cleanup()"| DataCenter

    %% Dependencies
    MonsterFamily --> DataCenter
    TowerFamily --> DataCenter
    Player --> DataCenter
    Bullet --> DataCenter
    UI --> DataCenter
    Shapes --> ImageCenter

    %% Click Events
    click algif5 "https://github.com/ycchnn/final-project/blob/main/algif5/algif.cpp"
    click Main "https://github.com/ycchnn/final-project/blob/main/Main.cpp"
    click Game "https://github.com/ycchnn/final-project/blob/main/Game.cpp"
    click Level "https://github.com/ycchnn/final-project/blob/main/Level.cpp"
    click UI "https://github.com/ycchnn/final-project/blob/main/UI.cpp"
    click DataCenter "https://github.com/ycchnn/final-project/blob/main/data/DataCenter.cpp"
    click FontCenter "https://github.com/ycchnn/final-project/blob/main/data/FontCenter.cpp"
    click GIFCenter "https://github.com/ycchnn/final-project/blob/main/data/GIFCenter.cpp"
    click ImageCenter "https://github.com/ycchnn/final-project/blob/main/data/ImageCenter.cpp"
    click SoundCenter "https://github.com/ycchnn/final-project/blob/main/data/SoundCenter.cpp"
    click OperationCenter "https://github.com/ycchnn/final-project/blob/main/data/OperationCenter.cpp"
    click MonsterFamily "https://github.com/ycchnn/final-project/blob/main/monsters/Monster.cpp"
    click TowerFamily "https://github.com/ycchnn/final-project/blob/main/towers/Tower.cpp"
    click Bullet "https://github.com/ycchnn/final-project/blob/main/towers/Bullet.cpp"
    click Player "https://github.com/ycchnn/final-project/blob/main/Player.cpp"
    click Object "https://github.com/ycchnn/final-project/blob/main/Object.h"
    click Hero "https://github.com/ycchnn/final-project/blob/main/hero.cpp"
    click Sun "https://github.com/ycchnn/final-project/blob/main/sun.cpp"
    click Shapes "https://github.com/ycchnn/final-project/blob/main/shapes/Shape.cpp"
    click Utils "https://github.com/ycchnn/final-project/blob/main/Utils.h"
    click Fonts "https://github.com/ycchnn/final-project/tree/main/assets/font/"
    click GIFs "https://github.com/ycchnn/final-project/tree/main/assets/gif/"
    click Images "https://github.com/ycchnn/final-project/tree/main/assets/image/"
    click Sounds "https://github.com/ycchnn/final-project/tree/main/assets/sound/"
    click Levels "https://github.com/ycchnn/final-project/tree/main/assets/level/"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#005CB9,color:#003366;
    classDef manager fill:#DFF5E0,stroke:#28A745,color:#155724;
    classDef entity fill:#FFE5B4,stroke:#FF8C00,color:#663300;
    classDef ext fill:#E0E0E0,stroke:#6C757D,color:#343A40;
    classDef asset fill:#FFF3CD,stroke:#FFCD39,color:#856404;
    classDef util fill:#F0E6FF,stroke:#6F42C1,color:#4B0082;
```
