A modern, cross-platform recreation of the iconic arcade classic Pac-Man, engineered in C# (.NET 10) using Avalonia UI. Built with strict adherence to Clean Architecture, MVVM, and SOLID principles, this project demonstrates robust desktop software engineering, real-time 2D canvas rendering, and authentic arcade Ghost AI targeting mechanics.
- Features
- Architecture & Design Patterns
- Project Structure
- Getting Started
- Controls & Keybindings
- License
- Classic Arcade Dynamics: Smooth continuous grid movement with directional pre-buffering (
NextDirection) for seamless turning at intersections. - Side Tunnels & Wrap-Around: Seamless horizontal screen-wrap mechanics.
- Score & Scoring System: Real-time scoring for standard pellets (10 pts), power pellets (50 pts), bonus fruits (100โ300 pts), and successive ghost captures (+200 pts).
- Life Management: 3 starting lives, respawn transitions, game over triggers, and victory conditions upon clearing the maze.
- Persistent High Scores: Top 5 scoreboard asynchronously saved to and loaded from
scores.json.
Each of the four ghosts faithfully implements the original 1980 Namco arcade targeting logic using the Strategy Pattern:
- Staggered Ghost House Release: Timed exit delays for Blinky (0s), Pinky (1.8s), Inky (4.8s), and Clyde (9s) with automatic base navigation.
- Frightened / Vulnerable Mode: Power pellets turn ghosts blue, reduce their speed by 50%, invert movement to pseudorandom navigation, and trigger warning flashing before returning to normal.
- Base Respawn: Eaten ghosts become eyes and navigate directly back to the ghost house to respawn.
- Non-blocking Multiplatform Audio Engine: Background music, eating effects, frightened sirens, jumpscare sound, game-over, and victory tunes powered by native system audio runners (
ffplay,pw-play,paplay,aplay,afplay, andPowerShell SoundPlayer). - High-Performance 2D Canvas: 60 FPS rendering via Avalonia Canvas, supporting frame-by-frame mouth animations, dynamic sprite orientation, and flashing effects.
- Jumpscare Effect: Optional visual & auditory overlay triggered on ghost collision.
The project follows Clean Architecture to maintain complete separation between domain entities, business logic, persistence mechanisms, and user interface components.
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ PRESENTATION LAYER โ
โ (Pacman.DesktopUI - MVVM) โ
โ MainWindow.axaml โโโโโบ MainViewModel โโโโบ PacmanBoardCanvas โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ References
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ APPLICATION LAYER โ
โ (Pacman.Application) โ
โ GameEngine (Facade) โโโบ GhostFactory | PlayerMovementHandler โ
โ โโโบ CollisionSystem | FrightenedModeManager โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ References
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ DOMAIN LAYER โ
โ (Pacman.Core) โ
โ Board, Player, Ghost, Position, Direction, Enums, TileType โ
โ IGhostMovementStrategy & Strategies (Blinky, Pinky, Inky, Clyde) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฒโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Implements domain abstractions
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ INFRASTRUCTURE LAYER โ
โ (Pacman.Infrastructure) โ
โ JsonScoreRepository (JSON I/O) | SoundManager (Process Audio) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
-
Pacman.Core(Domain Layer)- Zero external dependencies (pure C#).
- Houses domain entities (
Player,Ghost,Board), immutable value objects (Position), state enumerations, and AI movement strategy interfaces.
-
Pacman.Application(Application / Use Cases)- Orchestrates the game loop via
GameEngine(discrete tick cycle). - Manages subsystems:
CollisionSystem,PlayerMovementHandler,FrightenedModeManager, andGhostFactory.
- Orchestrates the game loop via
-
Pacman.Infrastructure(Infrastructure Layer)- Implements data persistence (
JsonScoreRepository) using asynchronousSystem.Text.Jsonstreaming. - Manages audio dispatching (
SoundManager) across operating systems.
- Implements data persistence (
-
Pacman.DesktopUI(Presentation Layer)- Built on Avalonia UI 11/12 and
CommunityToolkit.Mvvm. - Contains
MainWindow.axaml, reactiveMainViewModel, and custom graphics rendererPacmanBoardCanvas.
- Built on Avalonia UI 11/12 and
| Pattern | Implementation | Purpose |
|---|---|---|
| Strategy | IGhostMovementStrategy (Blinky, Pinky, Inky, Clyde) |
Encapsulates unique pursuit algorithms interchangeability at runtime. |
| Factory Method | GhostFactory |
Decouples ghost instantiation, strategy binding, and spawn positions. |
| Facade | GameEngine |
Exposes a unified API (Tick(), Start(), Pause()) hiding subsystem complexity. |
| MVVM | MainViewModel + Avalonia Views |
Enforces strict separation between UI presentation and business logic. |
| Dependency Inversion (DIP) | IScoreRepository, ISoundManager |
Presentation and Application depend on abstractions rather than low-level details. |
pacman-desktop/
โโโ Pacman.slnx # Solution configuration
โโโ Assets/ # Sprites, audio tracks, and maze definitions
โ โโโ pacman-art/ # Animated character and ghost sprites
โ โโโ maze.txt # Default 28x31 classic arcade maze
โ โโโ maze2.txt # Alternative custom maze layout
โ โโโ *.mp3 # Sound effects & soundtrack
โโโ Pacman.Core/ # Pure Domain Layer
โ โโโ Board.cs # Grid representation & wrap-around arithmetic
โ โโโ Position.cs # Readonly record struct with coordinate math
โ โโโ Player.cs # Pac-Man state & score tracking
โ โโโ Ghost.cs # Ghost entity & state definitions
โ โโโ GhostStrategies.cs # Blinky, Pinky, Inky, Clyde AI algorithms
โโโ Pacman.Application/ # Application & Orchestration Layer
โ โโโ GameEngine.cs # Central game loop coordinator
โ โโโ GhostFactory.cs # Ghost creation & positioning factory
โ โโโ PlayerMovementHandler.cs # Buffer validation & grid movement
โ โโโ CollisionSystem.cs # Pac-Man / Ghost interaction resolutions
โ โโโ FrightenedModeManager.cs # Timer-based vulnerability state machine
โโโ Pacman.Infrastructure/ # Persistence & Platform Services
โ โโโ JsonScoreRepository.cs # High score serialization (scores.json)
โ โโโ SoundManager.cs # Native cross-platform audio player
โโโ Pacman.DesktopUI/ # Avalonia UI Presentation Layer
โโโ ViewModels/ # MainViewModel (CommunityToolkit.Mvvm)
โโโ Views/ # MainWindow.axaml & PacmanBoardCanvas
โโโ appsettings.json # Runtime maze selection & settings
- .NET 10.0 SDK or later.
- OS: Linux (Ubuntu/Debian, Fedora, Arch, etc.), Windows 10/11, or macOS.
-
Clone the repository:
git clone https://github.com/Patick-gu/Pacman.git cd Pacman -
Restore dependencies:
dotnet restore
-
Build the solution:
dotnet build
-
Launch the game:
dotnet run --project Pacman.DesktopUI
You can easily switch maps or supply your own custom maze text file by editing Pacman.DesktopUI/appsettings.json:
{
"AppSettings": {
"Title": "PACMAN",
"MazePath": "Assets/maze.txt"
}
}#: Wall*: Standard Pellet (Dot)O: Power PelletP: Pac-Man Start Position-: Ghost House Gate: Empty Corridor / Wrap-Around Side Tunnel
| Action | Primary Key | Alternative Key |
|---|---|---|
| Move Up | โ (Up Arrow) |
W |
| Move Down | โ (Down Arrow) |
S |
| Move Left | โ (Left Arrow) |
A |
| Move Right | โ (Right Arrow) |
D |
| Pause / Resume | Space |
- |
| Mute / Unmute Audio | M |
- |
| Restart / Reload Game | F5 |
R |
| Return to Menu | Esc |
- |
| Start Game (from Menu) | Enter |
Space / Mouse Click |
This project is licensed under the MIT License โ see the LICENSE file for details.