# dhnguyencs/2048_cpp architecture

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

- Interactive diagram: https://gitdiagram.com/dhnguyencs/2048_cpp
- Repository: https://github.com/dhnguyencs/2048_cpp

## Overview

This is a small SFML 2048 game: keyboard input enters the main loop, which asks the board to apply moves and render each frame. The board owns the grid, score, random-tile placement, and move/merge logic; tiles carry the positions and animation state used when drawing. The rounded-rectangle shape supplies a custom drawing primitive. The excerpts show these core responsibilities, but omit parts of the board implementation, so the graph keeps them within the board component rather than inventing separate stages.

Main entry points: [`src/gameBoard.cpp`](https://github.com/dhnguyencs/2048_cpp/blob/main/src/gameBoard.cpp) (Board and game rules), [`src/main.cpp`](https://github.com/dhnguyencs/2048_cpp/blob/main/src/main.cpp) (Window and input loop), [`src/tile.cpp`](https://github.com/dhnguyencs/2048_cpp/blob/main/src/tile.cpp) (Tile state and animation), [`src/RoundedRectangleShape.cpp`](https://github.com/dhnguyencs/2048_cpp/blob/main/src/RoundedRectangleShape.cpp) (Rounded rectangle shape)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Game application"]
  node_main["Window and input loop<br/>[main.cpp]"]
end

subgraph group_domain["Game state"]
  node_board["Board and game rules<br/>[gameBoard.cpp]"]
  node_tile["Tile state and animation<br/>[tile.cpp]"]
end

subgraph group_graphics["Drawing"]
  node_rounded["Rounded rectangle shape"]
end

node_player(("Player"))

node_player -->|"presses keys"| node_main
node_main -->|"dispatches moves"| node_board
node_main -->|"requests rendering"| node_board
node_board -->|"updates and animates"| node_tile
node_board -->|"draws board background"| node_rounded

click node_main "https://github.com/dhnguyencs/2048_cpp/blob/main/src/main.cpp"
click node_board "https://github.com/dhnguyencs/2048_cpp/blob/main/src/gameBoard.cpp"
click node_tile "https://github.com/dhnguyencs/2048_cpp/blob/main/src/tile.cpp"
click node_rounded "https://github.com/dhnguyencs/2048_cpp/blob/main/src/RoundedRectangleShape.cpp"

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_board,node_tile toneAmber
class node_rounded toneMint
class node_player toneIndigo
```

## Components

### Game application

- [Window and input loop](https://github.com/dhnguyencs/2048_cpp/blob/main/src/main.cpp): `src/main.cpp`

### Game state

- [Board and game rules](https://github.com/dhnguyencs/2048_cpp/blob/main/src/gameBoard.cpp): `src/gameBoard.cpp`
- [Tile state and animation](https://github.com/dhnguyencs/2048_cpp/blob/main/src/tile.cpp): `src/tile.cpp`

### Drawing

- [Rounded rectangle shape](https://github.com/dhnguyencs/2048_cpp/blob/main/src/RoundedRectangleShape.cpp): `src/RoundedRectangleShape.cpp`

### Other components

- **Player**

## Connections

- Player → Window and input loop: presses keys (evidence: `src/main.cpp`)
- Window and input loop → Board and game rules: dispatches moves (evidence: `src/main.cpp`)
- Window and input loop → Board and game rules: requests rendering (evidence: `src/main.cpp`)
- Board and game rules → Tile state and animation: updates and animates (evidence: `src/gameBoard.cpp`)
- Board and game rules → Rounded rectangle shape: draws board background (evidence: `src/gameBoard.cpp`)
