# nawalkavi/hangman architecture

> Architecture diagram of the GitHub repository nawalkavi/hangman, 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/nawalkavi/hangman
- Repository: https://github.com/nawalkavi/hangman

## Overview

This is a Pygame Hangman game with two modes: the player guesses a randomly selected word, or the AI guesses a player-chosen word. The main loop in main.py owns screen navigation, input handling, and coordination of game state and rendering. User.py and Question.py implement the two guessing models; Text.py and Hangman.py support presentation. The README documents both modes, while the sampled excerpts do not show all setup, asset-loading, or result-screen wiring.

Main entry points: [`main.py`](https://github.com/nawalkavi/hangman/blob/main/main.py) (Game loop), [`Text.py`](https://github.com/nawalkavi/hangman/blob/main/Text.py) (Text buttons), [`Hangman.py`](https://github.com/nawalkavi/hangman/blob/main/Hangman.py) (Hangman display), [`User.py`](https://github.com/nawalkavi/hangman/blob/main/User.py) (Player guessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_flow["Game flow"]
  node_main["Game loop<br/>[main.py]"]
end

subgraph group_rules["Guessing logic"]
  node_user["Player guessing<br/>[User.py]"]
  node_question["AI guessing<br/>[Question.py]"]
end

subgraph group_view["Presentation and assets"]
  node_text["Text buttons<br/>[Text.py]"]
  node_hangman["Hangman display<br/>[Hangman.py]"]
  node_words["Word list<br/>[words.txt]"]
  node_images["Hangman images"]
  node_music["Sound effects"]
end

node_player(("Player"))
node_pygame["Pygame"]

node_player -->|"provides input"| node_main
node_main -->|"calls guessing"| node_user
node_main -->|"calls guessing"| node_question
node_main -->|"renders controls"| node_text
node_main -->|"renders stages"| node_hangman
node_main -->|"reads game state"| node_user
node_main -->|"reads game state"| node_question
node_text -->|"uses UI"| node_pygame
node_main -->|"handles events"| node_pygame
node_hangman -->|"draws image"| node_pygame
node_text -->|"plays hover sound"| node_music
node_main -.->|"asset setup"| node_images
node_main -.->|"word setup"| node_words

click node_main "https://github.com/nawalkavi/hangman/blob/main/main.py"
click node_user "https://github.com/nawalkavi/hangman/blob/main/User.py"
click node_question "https://github.com/nawalkavi/hangman/blob/main/Question.py"
click node_text "https://github.com/nawalkavi/hangman/blob/main/Text.py"
click node_hangman "https://github.com/nawalkavi/hangman/blob/main/Hangman.py"
click node_words "https://github.com/nawalkavi/hangman/blob/main/Assets/Word%20Dictionary/words.txt"
click node_images "https://github.com/nawalkavi/hangman/tree/main/Assets/Images/Hangman"
click node_music "https://github.com/nawalkavi/hangman/tree/main/Assets/Music"

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 toneBlue
class node_user,node_question toneAmber
class node_text,node_hangman,node_words,node_images,node_music toneMint
class node_player,node_pygame toneIndigo
```

## Components

### Game flow

- [Game loop](https://github.com/nawalkavi/hangman/blob/main/main.py): `main.py`

### Guessing logic

- [Player guessing](https://github.com/nawalkavi/hangman/blob/main/User.py): `User.py`
- [AI guessing](https://github.com/nawalkavi/hangman/blob/main/Question.py): `Question.py`

### Presentation and assets

- [Text buttons](https://github.com/nawalkavi/hangman/blob/main/Text.py): `Text.py`
- [Hangman display](https://github.com/nawalkavi/hangman/blob/main/Hangman.py): `Hangman.py`
- [Word list](https://github.com/nawalkavi/hangman/blob/main/Assets/Word%20Dictionary/words.txt): `Assets/Word Dictionary/words.txt`
- [Hangman images](https://github.com/nawalkavi/hangman/tree/main/Assets/Images/Hangman): `Assets/Images/Hangman`
- [Sound effects](https://github.com/nawalkavi/hangman/tree/main/Assets/Music): `Assets/Music`

### Other components

- **Player**
- **Pygame**

## Connections

- Player → Game loop: provides input
- Game loop → Player guessing: calls guessing
- Game loop → AI guessing: calls guessing
- Game loop → Text buttons: renders controls
- Game loop → Hangman display: renders stages
- Game loop → Player guessing: reads game state
- Game loop → AI guessing: reads game state
- Text buttons → Pygame: uses UI
- Game loop → Pygame: handles events
- Hangman display → Pygame: draws image
- Text buttons → Sound effects: plays hover sound
- Game loop → Hangman images: asset setup
- Game loop → Word list: word setup
