# gaurab-arl/space_war_game architecture

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

- Interactive diagram: https://gitdiagram.com/gaurab-arl/space_war_game
- Repository: https://github.com/gaurab-arl/space_war_game

## Overview

Space War is a graphics.h arcade game: the player enters a name, navigates the menu, plays a survival-and-scoring loop, and can review saved high scores. The game separates menu/history UI, gameplay, collision and score rules, and file-backed history. The README documents horizontal and descending enemies, player and sky bullets, health, and multiple screens; sampled code supports the main call relationships shown here. Some game-loop details were omitted from the excerpts, so uncertain internal wiring is not shown.

Main entry points: [`gameui.cpp`](https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp) (Game loop), [`userui.cpp`](https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp) (User menu), [`main.cpp`](https://github.com/gaurab-arl/space_war_game/blob/main/main.cpp) (Application entry), [`collision.cpp`](https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp) (Collision handling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry and screens"]
  node_main["Application entry<br/>[main.cpp]"]
  node_name["Name input<br/>[userui.cpp]"]
  node_menu["User menu<br/>[userui.cpp]"]
  node_history_screen["History screen<br/>[userui.cpp]"]
  node_dispatch["Menu click handler<br/>[userui.cpp]"]
  node_background["Space background"]
end

subgraph group_play["Gameplay"]
  node_game["Game loop<br/>[gameui.cpp]"]
  node_ship["Ship and controls<br/>[gameui.cpp]"]
  node_projectiles["Bullet systems<br/>[gameui.cpp]"]
  node_enemies["Enemy movement<br/>[gameui.cpp]"]
end

subgraph group_rules["Game rules"]
  node_collisions["Collision handling<br/>[collision.cpp]"]
  node_health["Health and game over<br/>[collision.cpp]"]
  node_scoring["Score and level-up<br/>[collision.cpp]"]
end

subgraph group_records["History records"]
  node_fileops["History operations<br/>[fileop.cpp]"]
  node_history[("Saved scores<br/>[history.txt]")]
end

node_player(("Player"))

node_player -->|"starts game"| node_main
node_main -->|"requests name"| node_name
node_main -->|"shows menu"| node_menu
node_player -->|"clicks"| node_menu
node_menu -->|"handles clicks"| node_dispatch
node_dispatch -->|"starts play"| node_game
node_dispatch -->|"opens history"| node_history_screen
node_player -->|"keyboard input"| node_ship
node_game -->|"updates and draws"| node_ship
node_game -->|"updates and draws"| node_projectiles
node_game -->|"moves and draws"| node_enemies
node_game -->|"checks hits"| node_collisions
node_game -->|"updates score"| node_scoring
node_collisions -->|"reduces health"| node_health
node_collisions -->|"awards points"| node_scoring
node_health -->|"shows game over"| node_game
node_game -->|"saves score"| node_fileops
node_history_screen -->|"loads and sorts"| node_fileops
node_fileops -->|"reads and writes"| node_history
node_menu -->|"draws image"| node_background
node_history_screen -->|"draws image"| node_background
node_name -->|"draws image"| node_background

click node_main "https://github.com/gaurab-arl/space_war_game/blob/main/main.cpp"
click node_name "https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp"
click node_menu "https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp"
click node_history_screen "https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp"
click node_dispatch "https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp"
click node_game "https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp"
click node_ship "https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp"
click node_projectiles "https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp"
click node_enemies "https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp"
click node_collisions "https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp"
click node_health "https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp"
click node_scoring "https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp"
click node_fileops "https://github.com/gaurab-arl/space_war_game/blob/main/fileop.cpp"
click node_history "https://github.com/gaurab-arl/space_war_game/blob/main/history.txt"
click node_background "https://github.com/gaurab-arl/space_war_game/blob/main/assets/deep_space_background.bmp"

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_name,node_menu,node_history_screen,node_dispatch,node_background toneBlue
class node_game,node_ship,node_projectiles,node_enemies toneAmber
class node_collisions,node_health,node_scoring toneMint
class node_fileops,node_history toneRose
class node_player toneIndigo
```

## Components

### Entry and screens

- [Application entry](https://github.com/gaurab-arl/space_war_game/blob/main/main.cpp): `main.cpp`
- [Name input](https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp): `userui.cpp`
- [User menu](https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp): `userui.cpp`
- [History screen](https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp): `userui.cpp`
- [Menu click handler](https://github.com/gaurab-arl/space_war_game/blob/main/userui.cpp): `userui.cpp`
- [Space background](https://github.com/gaurab-arl/space_war_game/blob/main/assets/deep_space_background.bmp): `assets/deep_space_background.bmp`

### Gameplay

- [Game loop](https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp): `gameui.cpp`
- [Ship and controls](https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp): `gameui.cpp`
- [Bullet systems](https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp): `gameui.cpp`
- [Enemy movement](https://github.com/gaurab-arl/space_war_game/blob/main/gameui.cpp): `gameui.cpp`

### Game rules

- [Collision handling](https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp): `collision.cpp`
- [Health and game over](https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp): `collision.cpp`
- [Score and level-up](https://github.com/gaurab-arl/space_war_game/blob/main/collision.cpp): `collision.cpp`

### History records

- [History operations](https://github.com/gaurab-arl/space_war_game/blob/main/fileop.cpp): `fileop.cpp`
- [Saved scores](https://github.com/gaurab-arl/space_war_game/blob/main/history.txt): `history.txt`

### Other components

- **Player**

## Connections

- Player → Application entry: starts game
- Application entry → Name input: requests name
- Application entry → User menu: shows menu
- Player → User menu: clicks
- User menu → Menu click handler: handles clicks
- Menu click handler → Game loop: starts play
- Menu click handler → History screen: opens history
- Player → Ship and controls: keyboard input
- Game loop → Ship and controls: updates and draws
- Game loop → Bullet systems: updates and draws
- Game loop → Enemy movement: moves and draws
- Game loop → Collision handling: checks hits
- Game loop → Score and level-up: updates score
- Collision handling → Health and game over: reduces health
- Collision handling → Score and level-up: awards points
- Health and game over → Game loop: shows game over
- Game loop → History operations: saves score
- History screen → History operations: loads and sorts
- History operations → Saved scores: reads and writes
- User menu → Space background: draws image
- History screen → Space background: draws image
- Name input → Space background: draws image
