- Overview
- System Features
- Class Diagram
- Design Patterns Used
- Component-Level Details
- Gameplay Workflow
This project implements a fully modular, extensible Snakes & Ladders game in C++, designed with clean OOP principles and multiple design patterns.
The system supports:
- Multiple board setup strategies
- Custom, random, and standard configurations
- Observer-based notifications
- Multiple players
- Pluggable rules
The goal of the architecture is to allow flexible extension—for example, additional rules, new board strategies, or UI-based observers—without modifying core logic.
- Standard strategy → canonical 10×10 board
- Random strategy → difficulty-based snake/ladder distribution
- Custom strategy
- Random placement using custom counts
- Exact user-defined positions
The game publishes events (moves, encounters, wins) to all observers.
Default implementation: SnakeAndLadderConsoleNotifier
Rules for:
- Move validity
- Snake/ladder traversal
- Win condition
Handled by SnakeAndLadderRules and its derivative StandardSnakeAndLadderRules.
Each player has:
- Name
- Current position
- Win count
SnakeAndLadderGameFactory builds:
- Standard game
- Random game
- Custom game
The following diagram shows all major system components and relationships:
Used to broadcast game events to any number of observers.
Subject:
SnakeAndLadderGame
Observers:
IObserverinterfaceSnakeAndLadderConsoleNotifier
This makes logging and UI updates plug-and-play.
Used in two major subsystems:
BoardSetupStrategy(abstract)RandomBoardSetupStrategyCustomCountBoardSetupStrategyStandardBoardSetupStrategy
Allows dynamic selection of board initialization logic.
SnakeAndLadderRulesStandardSnakeAndLadderRules
Allows different move/win interpretations.
SnakeAndLadderGameFactory helps construct a game without directly exposing creation details:
createStandardGame()createRandomGame(boardSize, difficulty)createCustomGame(boardSize, strategy)
This keeps main logic clean and encourages modularity.
Defines event-handling wrappers to print or extend notifications.
class IObserver {
public:
virtual void update(string msg) = 0;
};Encapsulates dice face count and random rolling.
faces: introll(): int
Stores:
totalCellssnakes: List<Snake>ladders: List<Ladder>entityMap: Map<Int, BoardEntity>(fast lookup)
startIndexendIndex
- Difficulty-based snake probabilities
- Random count placement
- Avoid overlapping entities
- User-defined snakes/ladders
- Classic snake & ladder layout
Each implements:
apply(board: Board): Board
Stores:
idnamecurrentPositionwinCount
Controls:
- Move validation
- Boundary checks
- Snake/ladder traversal
- Win condition
Default implementation:
- Exact landing needed to win
- Automatically apply snake/ladder effect
Coordinates gameplay:
- Manages board
- Rolls dice
- Tracks turn order (
Deque<Player>) - Broadcasts events
- Uses rule strategy
Responsibilities:
startGame()playTurn()applyRules()notifyObservers()
Builds entire game setup:
- Board creation
- Strategy application
- Dice initialization
- Players added
- Observers attached
Zero redundant logic in main game loop.
-
Player chooses configuration
- Standard
- Random
- Custom
-
Factory builds game
-
Board is created
-
Strategy applied
-
Dice initialized
-
Players added
-
Observers attached
-
Game loop begins
- Roll
- Validate move
- Apply snakes/ladders
- Notify observers
- Check win
-
Game ends when player reaches final cell
