How mishpajz-fit/bi-pa2-pacman works
Project Type and Purpose
• Type: Single‑binary C++ game, playable in terminal, structured with a simplified Model‑View‑ViewModel (MVVM) approach.
• Purpose: Render a Pacman clone using ncurses, load/save maps and settings, manage game states and AI, and persist high scores.
Main Architectural Components
A. Model Layer (Game State & Logic)
• GameLogic/
– Board (grid, cells, teleportation)
– Entities (Player, Enemy base, Ghosts with AI modes)
– Game (orchestrates tick/update, collision)
• AppState (current lives, score, level)
• StateManager (tracks which UI or game state is active)
B. ViewModel & Controllers
• ViewControllers/
– MainMenuViewController (handles menu navigation)
– GameViewController (relays input to game logic, triggers updates)
– ViewController base (common input/output glue)
• Utilities/Contexts/
– GameControl, GameSettings, GameRecords, OptionMenu contexts (shared state buckets for VMs)
C. View Layer (Rendering)
• Views/
– LayoutView, LoadingView, LogoView, GameView, GameOverView
– SecondaryViews (OptionMenuView, SettingsView, GameDetailView)
D. Persistence & Configuration
• Utilities/FileManagers/
– FileManager (generic I/O)
– BoardFileLoader (map parsing)
– GameSettingsRecordsFileLoader/Saver (load/save high scores & settings)
E. Infrastructure & Utilities
• Utilities/Timer (schedules game ticks)
• Structures/Transforms & Matrix (geometry helpers)
F. Entry Point
• main.cpp
– Bootstraps: parses args, initializes ncurses, loads config & map, enters main loop via StateManager
Component Interactions & Data Flow
• main.cpp → StateManager: start in MainMenu state
• MainMenuViewController ←→ Utilities/Contexts: read menu options
• Upon “Start Game”: GameViewController calls GameLogic::Game.update() each tick via Timer
• Game.update() manipulates Board & Entities → updates AppState (score, lives)
• GameRecordsContext & FileManagers: persist high‑score on game end
• Input from user flows from View → Controller → Model
Architectural Patterns & Design Principles
• MVVM‑inspired separation:
– Model: pure game logic, no UI code
– ViewModel/Controllers: mediate between UI & logic, hold contexts
– View: pure rendering, no logic
• Single responsibility: each FileManager handles one file type
• Dependency direction: high‑level controllers depend on lower‑level utilities, not vice versa
Final Checklist
[ ] Main components boxed & labeled
[ ] Layers separated: Persistence → Model → Controllers → View → External
[ ] Notes on patterns (MVVM, single responsibility) included in a sidebar