How aaronalam1987/tetris works
Project Type and Purpose
• Type: Single‐player desktop game application (Tetris clone).
• Purpose: Real‐time interactive puzzle game with rendering, audio, input handling, game state management, and persistence of high scores.
File Structure
• Top‐level code files:
• main.cpp / main.h: application entry point, game loop orchestration
• inputMonitor.*: captures and normalizes player input
• graphics.*: rendering board, blocks, UI (start screen, next‐piece preview, game over)
• audio.*: playing SFX and music via SFML audio module
• highScores.*: reading/writing scores.json using nlohmann::json
• assets/: all multimedia assets (sprites, sound files)
• nlohmann/json.hpp: JSON parsing library for high-score persistence
README Insights
• Uses SFML 2.5.1 for windowing, graphics, audio, and event handling.
• Makefile produces statically‐linked executable.
• Controls, features (start screen, dynamic speed, next‐block preview, high scores).
Main Components & Interactions
a. Components to include:
1. Application Entry (main) & Game Loop
2. Input Subsystem (InputMonitor)
3. Game Logic Subsystem (PieceManager + Pieces + Global State)
4. Rendering Subsystem (Graphics)
5. Audio Subsystem (Audio)
6. Persistence Subsystem (HighScores + JSON)
7. Asset Store (assets/ folder)
8. External Libraries: SFML (Graphics, Window, Audio, System), nlohmann::json
b. Relationships:
• The Game Loop invokes:
• InputMonitor → collects SFML events → dispatches commands to Game Logic
• Game Logic → updates board state, score, next piece
• Graphics → reads board state, UI state → draws to SFML window
• Audio → plays BGM and SFX based on Game Logic events
• HighScores → on game over, reads/writes scores.json
• Asset Store → loaded by Graphics and Audio at startup
• SFML libs → underlying calls for window creation, drawing, audio playback, event polling
c. Architectural Patterns & Principles:
• Modular separation of concerns: input, logic, rendering, audio, persistence
• Single responsibility per module
• Resource management via central asset folder
• Game loop pattern (init → process input → update → render → repeat)
d. Key Technologies & Libraries:
• C++17 (or later)
• SFML 2.5.1 (Graphics, Window, Audio, System)
• nlohmann/json for JSON I/O
• Makefile / Visual Studio Code configuration for build
Elements
• Clear labels: e.g., “InputMonitor Module,” “PieceManager Module,” “Graphics Module,” etc.
• Input → Game Logic
• Game Logic → Rendering & Audio & Persistence (on game over)
• Rendering/Audio → SFML Library
• Persistence ↔ JSON Library & scores.json
• Graphics/Audio ↔ Asset Store