# nu7h/comp2113_minigame_project architecture

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

- Interactive diagram: https://gitdiagram.com/nu7h/comp2113_minigame_project
- Repository: https://github.com/nu7h/comp2113_minigame_project

## Overview

1. This is a single-player C++ terminal game built as one executable (`make && ./build/game`). The architecture is centered on an update/render loop driven by `main.cpp`, with all gameplay presented as ASCII art and text rather than graphics APIs.

2. `Game` is the top-level orchestrator. It likely owns the current mode/state, runs the main loop, coordinates input, updates entities, handles room transitions, and decides when to show cutscenes, gameplay, pause, or outro screens. `GameState.h` and `Difficulty.h` provide the shared state/config enums used across the codebase.

3. `Render` is the presentation boundary. It turns the current game state into console output: room geometry, player/enemy symbols, hearts, attack particles, projectiles, lock indicators, and the HUD. The README’s symbol table maps directly to this rendering layer.

4. `Map` is the world/layout subsystem. It reads room files from the `room/` directory and likely exposes collision data, exits, and room-specific logic such as blocked doors until enemies are defeated. Room transitions are data-driven through these text maps rather than hardcoded level geometry.

5. `Entity` is the shared gameplay abstraction. `Player` and `Enemy` derive from it, which suggests common fields like position, health, direction, and update/collision behavior. This is the main object model for in-game actors.

6. `Player` handles movement, facing direction, attacks, shield activation, invincibility frames, and health changes. Its state is reflected both in gameplay logic and in the HUD. The README indicates the player can attack, block projectiles, and take temporary damage immunity after hits.

7. `Enemy` encapsulates slime/boss behavior. Enemies can wander, chase the player, and fire projectiles when in range. Their per-room count and speed depend on the selected difficulty, so `Enemy` is tied to both AI behavior and difficulty scaling.

8. `Cutscene` is a separate content-and-flow subsystem used for intro/outro sequences. It reads scripted text/ASCII art from `Intro/` and `Outro/` assets, which keeps narrative presentation outside the core room-combat loop. This makes the game’s opening and ending flow distinct from normal gameplay.

9. `Input` is the control boundary between keyboard events and game actions. The README shows direct mappings for movement, attack, shield, pause, quit, and save/continue decisions. `Game` likely consumes input and dispatches it to player movement or global state changes.

10. The main data flow is: keyboard input -> `Game` state update -> `Player`/`Enemy`/`Map` logic -> collision/combat/resolution -> `Render` output. The game loop is therefore state-driven and frame-based, with map data and entity state feeding the renderer every cycle.

11. Persistence is local and lightweight. The README describes save/load on quit and restart, storing room, player position, difficulty, and enemy states. That makes save handling another cross-cutting concern owned by `Game`, not a separate service.

12. Content is heavily externalized into text assets. `room/*.txt` defines playable areas, while `Intro/` and `Outro/` contain scripted scenes and ASCII art. That separation means the engine is relatively small, and most variation comes from data files rather than code.

13. Overall boundaries are clean: `main` boots the app, `Game` manages progression, `Map` defines space, `Entity`/`Player`/`Enemy` define actors, `Render` draws, `Input` reads controls, and `Cutscene` handles narrative screens. This is a classic console game architecture with data-driven rooms and a simple state machine at the center.

Main entry points: [`Game.h`](https://github.com/nu7h/comp2113_minigame_project/blob/main/Game.h) (Game), [`Render.h`](https://github.com/nu7h/comp2113_minigame_project/blob/main/Render.h) (Render), [`Enemy.h`](https://github.com/nu7h/comp2113_minigame_project/blob/main/Enemy.h) (Enemy), [`Map.h`](https://github.com/nu7h/comp2113_minigame_project/blob/main/Map.h) (Map)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core loop"]
  node_main["main<br/>entrypoint<br/>[main.cpp]"]
  node_game["Game<br/>orchestrator<br/>[Game.h]"]
  node_state["State<br/>[GameState.h]"]
  node_difficulty["Difficulty<br/>config enum<br/>[Difficulty.h]"]
  node_input["Input<br/>control boundary<br/>[Input.h]"]
  node_build["Makefile<br/>build config"]
end

subgraph group_world["World & actors"]
  node_map[("Map<br/>world loader<br/>[Map.h]")]
  node_entity["Entity<br/>base actor<br/>[Entity.h]"]
  node_player["Player<br/>actor<br/>[Player.h]"]
  node_enemy["Enemy<br/>AI actor<br/>[Enemy.h]"]
end

subgraph group_presentation["Presentation"]
  node_render["Render<br/>[Render.h]"]
  node_cutscene["Cutscene<br/>scripted scenes<br/>[Cutscene.h]"]
end

subgraph group_assets["Content"]
  node_intro["Intro assets<br/>scene text"]
  node_outro["Outro assets<br/>scene text"]
  node_rooms["Room files<br/>level text"]
  node_readme["README<br/>game rules<br/>[README.md]"]
end

node_main -->|"starts"| node_game
node_game -->|"uses"| node_state
node_game -->|"uses"| node_difficulty
node_game -->|"consumes"| node_input
node_game -->|"loads"| node_map
node_game -->|"updates"| node_player
node_game -->|"updates"| node_enemy
node_game -->|"draws"| node_render
node_game -->|"switches to"| node_cutscene
node_map -->|"reads"| node_rooms
node_player -->|"inherits"| node_entity
node_enemy -->|"inherits"| node_entity
node_player -->|"collides with"| node_map
node_enemy -->|"spawns in"| node_map
node_enemy -->|"scales with"| node_difficulty
node_render -->|"visualizes"| node_map
node_render -->|"visualizes"| node_player
node_render -->|"visualizes"| node_enemy
node_render -->|"reflects"| node_state
node_cutscene -->|"reads"| node_intro
node_cutscene -->|"reads"| node_outro
node_readme -.->|"documents"| node_input
node_readme -.->|"documents"| node_render
node_build -->|"builds"| node_main

click node_main "https://github.com/nu7h/comp2113_minigame_project/blob/main/main.cpp"
click node_game "https://github.com/nu7h/comp2113_minigame_project/blob/main/Game.h"
click node_state "https://github.com/nu7h/comp2113_minigame_project/blob/main/GameState.h"
click node_difficulty "https://github.com/nu7h/comp2113_minigame_project/blob/main/Difficulty.h"
click node_input "https://github.com/nu7h/comp2113_minigame_project/blob/main/Input.h"
click node_map "https://github.com/nu7h/comp2113_minigame_project/blob/main/Map.h"
click node_entity "https://github.com/nu7h/comp2113_minigame_project/blob/main/Entity.h"
click node_player "https://github.com/nu7h/comp2113_minigame_project/blob/main/Player.h"
click node_enemy "https://github.com/nu7h/comp2113_minigame_project/blob/main/Enemy.h"
click node_render "https://github.com/nu7h/comp2113_minigame_project/blob/main/Render.h"
click node_cutscene "https://github.com/nu7h/comp2113_minigame_project/blob/main/Cutscene.h"
click node_intro "https://github.com/nu7h/comp2113_minigame_project/tree/main/Intro"
click node_outro "https://github.com/nu7h/comp2113_minigame_project/tree/main/Outro"
click node_rooms "https://github.com/nu7h/comp2113_minigame_project/tree/main/room"
click node_readme "https://github.com/nu7h/comp2113_minigame_project/blob/main/README.md"
click node_build "https://github.com/nu7h/comp2113_minigame_project/tree/main/Makefile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_game,node_state,node_difficulty,node_input,node_build toneBlue
class node_map,node_entity,node_player,node_enemy toneAmber
class node_render,node_cutscene toneMint
class node_intro,node_outro,node_rooms,node_readme toneRose
```

## Components

### Core loop

Runtime orchestration and shared game state.

- [main](https://github.com/nu7h/comp2113_minigame_project/blob/main/main.cpp): entrypoint · Boots the executable and starts the game loop. · `main.cpp`
- [Game](https://github.com/nu7h/comp2113_minigame_project/blob/main/Game.h): orchestrator · Owns mode flow, update loop, transitions, and save/load. · `Game.h`
- [State](https://github.com/nu7h/comp2113_minigame_project/blob/main/GameState.h): state enum · Shared game-mode states used across the loop. · `GameState.h`
- [Difficulty](https://github.com/nu7h/comp2113_minigame_project/blob/main/Difficulty.h): config enum · Global difficulty settings for scaling gameplay. · `Difficulty.h`
- [Input](https://github.com/nu7h/comp2113_minigame_project/blob/main/Input.h): control boundary · Maps keyboard events to actions and global commands. · `Input.h`
- [Makefile](https://github.com/nu7h/comp2113_minigame_project/tree/main/Makefile): build config · Builds the single executable. · `Makefile`

### World & actors

Map data and in-game entities.

- [Map](https://github.com/nu7h/comp2113_minigame_project/blob/main/Map.h): world loader · Loads room layouts and collision/transition data from text maps. · `Map.h`
- [Entity](https://github.com/nu7h/comp2113_minigame_project/blob/main/Entity.h): base actor · Shared actor interface for position, health, and updates. · `Entity.h`
- [Player](https://github.com/nu7h/comp2113_minigame_project/blob/main/Player.h): actor · Handles movement, facing, attacks, shield, and invincibility. · `Player.h`
- [Enemy](https://github.com/nu7h/comp2113_minigame_project/blob/main/Enemy.h): AI actor · Implements slime and boss behavior, chasing, and projectiles. · `Enemy.h`

### Presentation

Console rendering and scripted scenes.

- [Render](https://github.com/nu7h/comp2113_minigame_project/blob/main/Render.h): console renderer · Draws the room, actors, HUD, and combat effects to the terminal. · `Render.h`
- [Cutscene](https://github.com/nu7h/comp2113_minigame_project/blob/main/Cutscene.h): scripted scenes · Runs intro and outro sequences outside normal gameplay. · `Cutscene.h`

### Content

Text assets that drive rooms and cutscenes.

- [Intro assets](https://github.com/nu7h/comp2113_minigame_project/tree/main/Intro): scene text · ASCII art and scripted intro frames. · `Intro`
- [Outro assets](https://github.com/nu7h/comp2113_minigame_project/tree/main/Outro): scene text · ASCII art and scripted ending frames. · `Outro`
- [Room files](https://github.com/nu7h/comp2113_minigame_project/tree/main/room): level text · Data-driven room layouts and blocked-door layouts. · `room`
- [README](https://github.com/nu7h/comp2113_minigame_project/blob/main/README.md): game rules · Documents controls, symbols, save flow, and content mapping. · `README.md`

## Connections

- main → Game: starts · main creates and runs the game loop.
- Game → State: uses · Game drives mode changes through shared state.
- Game → Difficulty: uses · Difficulty affects scaling and progression.
- Game → Input: consumes · Game reads controls and global commands.
- Game → Map: loads · Game selects and updates the active room.
- Game → Player: updates · Game applies input and progression to the player.
- Game → Enemy: updates · Game advances enemy AI and combat.
- Game → Render: draws · Game sends current state to the renderer.
- Game → Cutscene: switches to · Game enters intro/outro flows when needed.
- Map → Room files: reads · Room layouts come from text files.
- Player → Entity: inherits · Player extends the shared actor base.
- Enemy → Entity: inherits · Enemy extends the shared actor base.
- Player → Map: collides with · Player movement is constrained by room geometry.
- Enemy → Map: spawns in · Enemies live inside loaded rooms.
- Enemy → Difficulty: scales with · Enemy count and speed vary by difficulty.
- Render → Map: visualizes · Renderer draws room geometry and exits.
- Render → Player: visualizes · Renderer shows player position and status.
- Render → Enemy: visualizes · Renderer shows enemies and combat effects.
- Render → State: reflects · HUD and screen content depend on current mode.
- Cutscene → Intro assets: reads · Intro sequences are sourced from scene text files.
- Cutscene → Outro assets: reads · Outro sequences are sourced from ending text files.
- README → Input: documents · Controls and key mappings are described here.
- README → Render: documents · Symbol table explains rendered ASCII elements.
- Makefile → main: builds · Makefile compiles the executable entrypoint.
