Skip to content
Patick-guPublic

About

A cross-platform Pac-Man arcade game built in C# (.NET 10) & Avalonia UI, featuring Clean Architecture, MVVM, and authentic arcade Ghost AI algorithms

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

ย 

History

15 Commits

Folders and files

NameName
Last commit message
Last commit date
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŸก Pac-Man Desktop

.NET Avalonia UI C# Architecture Cross Platform License: MIT

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.


๐Ÿ“‘ Table of Contents


โœจ Features

๐Ÿ•น๏ธ Core Gameplay

  • 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.

๐Ÿ‘ป Authentic Ghost AI Personalities

Each of the four ghosts faithfully implements the original 1980 Namco arcade targeting logic using the Strategy Pattern:

Ghost Character / Nickname Targeting Behavior
Blinky Shadow (Red) Direct Chaser: Aggressively targets Pac-Man's exact tile coordinates.
Pinky Speedy (Pink) Ambusher: Predicts movement, targeting 4 tiles ahead of Pac-Man's current vector.
Inky Bashful (Cyan) Flanker / Complex Vector: Computes an offset vector between Blinky and 2 tiles ahead of Pac-Man, mirroring it for pincer attacks.
Clyde Pokey (Orange) Shy / Coward: Pursues Pac-Man when distance $\ge 8$ tiles; retreats to his home corner when within 8 tiles.
  • 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.

๐Ÿ”Š Audio & Visual Systems

  • 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, and PowerShell 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.

๐Ÿ›๏ธ Architecture & Design Patterns

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)      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿงฉ Layer Breakdown

  1. 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.
  2. Pacman.Application (Application / Use Cases)

    • Orchestrates the game loop via GameEngine (discrete tick cycle).
    • Manages subsystems: CollisionSystem, PlayerMovementHandler, FrightenedModeManager, and GhostFactory.
  3. Pacman.Infrastructure (Infrastructure Layer)

    • Implements data persistence (JsonScoreRepository) using asynchronous System.Text.Json streaming.
    • Manages audio dispatching (SoundManager) across operating systems.
  4. Pacman.DesktopUI (Presentation Layer)

    • Built on Avalonia UI 11/12 and CommunityToolkit.Mvvm.
    • Contains MainWindow.axaml, reactive MainViewModel, and custom graphics renderer PacmanBoardCanvas.

๐Ÿ’ก Design Patterns Applied

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.

๐Ÿ“ Project Structure

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

๐Ÿš€ Getting Started

Prerequisites

  • .NET 10.0 SDK or later.
  • OS: Linux (Ubuntu/Debian, Fedora, Arch, etc.), Windows 10/11, or macOS.

Building and Running

  1. Clone the repository:

    git clone https://github.com/Patick-gu/Pacman.git
    cd Pacman
  2. Restore dependencies:

    dotnet restore
  3. Build the solution:

    dotnet build
  4. Launch the game:

    dotnet run --project Pacman.DesktopUI

๐Ÿ—บ๏ธ Custom Maze Configuration

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"
  }
}

Maze Legend Symbols:

  • # : Wall
  • * : Standard Pellet (Dot)
  • O : Power Pellet
  • P : Pac-Man Start Position
  • - : Ghost House Gate
  • : Empty Corridor / Wrap-Around Side Tunnel

๐ŸŽฎ Controls & Keybindings

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

๐Ÿ“„ License

This project is licensed under the MIT License โ€” see the LICENSE file for details.

About

A cross-platform Pac-Man arcade game built in C# (.NET 10) & Avalonia UI, featuring Clean Architecture, MVVM, and authentic arcade Ghost AI algorithms

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages