Design Class Diagrams for Monopoly Game
Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2024-06-17
Problem Statement
Designing the class diagrams for the classic board game Monopoly. The system should model players, the board, properties, money transactions, and game rules in an object-oriented design that can support turn-based play.
Functional Requirements (FR)
Game Setup
•A board with 40 spaces (properties, utilities, railroads, chance, community chest, tax, jail, free parking, go to jail, go).
•2–6 players can join a game.
•Each player starts with an initial balance and token.
Player Actions
•Roll dice and move their token.
•Buy unowned properties.
•Pay rent when landing on owned properties.
•Draw Chance/Community Chest cards and follow instructions.
•Pay taxes or fees when applicable.
•Mortgage/unmortgage properties.
•Build houses/hotels on owned monopolies.
•Trade properties with other players.
•Handle jail rules (pay bail, roll doubles, use “Get Out of Jail Free” card).
Property & Rent System
•Properties have purchase price, rent values, mortgage value, build cost.
•Rent varies based on houses/hotels and monopoly ownership.
Game Flow
•Players take turns sequentially.
•Handle bankruptcy (player eliminated when unable to pay).
•Game ends when one player remains or house rules decide a winner.
Cards
•Chance and Community Chest cards have effects like move, pay, receive money, jail, etc.
Non-Functional Requirements (NFR)
•Extensibility: Easy to add new rule variations (house rules).
•Maintainability: Clear OOP design with reusable components.
•Scalability: Should handle multiple games running simultaneously.
Core Entities & Attributes
Game
•players, board, dice, currentTurn
Board
•spaces (list of Square objects)
Square (abstract)
•position, name
•Subclasses: PropertySquare, UtilitySquare, RailroadSquare, ChanceSquare, CommunityChestSquare, TaxSquare, JailSquare, GoSquare, FreeParkingSquare, GoToJailSquare
Player
•playerId, name, token, balance, propertiesOwned, position, inJailStatus
Dice
•numDice, roll()
Property
•propertyId, name, price, rent[], mortgageValue, owner, houses, hotels
Card (abstract)
•description, action()
•Subclasses: ChanceCard, CommunityChestCard
Bank
•manages money transactions, houses, hotels, mortgages
Key Operations / Methods
Game
•startGame(), endGame(), nextTurn()
Player
•rollDice(), move(steps), buyProperty(), payRent(), declareBankruptcy(), trade()
Property
•calculateRent(), mortgage(), buildHouse(), buildHotel()
Card
•executeAction(player)
Advanced Features (Optional / Bonus)
•AI players / bots.
•Multiple variants (speed die, house rules).
•Online multiplayer support.
•Event logging (for replay/debug).