- Project Overview
- What Monopoly's functionalities we've implemented
- The Decorator Design Pattern
- The Factory Design Pattern
- The Singleton Design Pattern
We have decided to create multiple classes (you also see abstract classes on the image above) for our solution to the project.
Here is a brief explanation of each :
-
Board.cs : This is our singleton design pattern class, it will instantiate a unique board for our game, with all the properties and cards and jail !
-
Card.cs : This is an the product of our factory pattern, cards have different types of actions : give or take money, move players...
-
CardFactory : The Factory for the product Cards, we'll just have to give a position in the future to create one for the board
-
Game.cs : The "big" class, that monitors the game in terms of UI, create a board, called from the very beginning to the very end.
-
Player.cs : This class enables us to monitor player's ressources (money, properties, jail or not) and his position very easily after instanciation
-
*Program.cs" : Contains our main function, very simple & basic but we wanted it to be clear (create a game)!
-
Property.cs : As we know, Monopoly's Board is not only about getting cards, but also properties. This class enables us to manipulate property, reading their values, names, etc...
-
PropertyDecorator.cs : This contains the decorator pattern that we wanted to implement, we use it when a property changes its state : bought / player has bought a house / player has bought a hotel : we'll discuss this more in-depth later.
-
Square : Our board is made of Squares that can be properties, cards, taxes or jail ! But all these share the same instance : a position !
-
SquareFactory : Part of the factory pattern !
- 2-6 players
- Random Dice Rolling
-
40 Square Board
-
All properties implemented with options to buy, add house and add hotels to increase future revenues
- Chances Cards and Community_Chest Cards implemented with random events : earn money, pay taxes, move backwards or forwards...
- Jail option added
-
Players win when their opponents gave up or lost all their money
-
Players earn money each tour they make.
-
Players have to pay taxes if they are on another's one property
- Dashboard option to see our information
- Game Status Option
We chose to use this pattern in order for our properties to be evolving during the course of the game. First, their situation : bought or not. Then, if a player chose to buy a house or a hotel for this property, the taxes should be changing as well. At first, we had the ambition to use it as well to group properties (Streets so the tax rise up and we build up to 5 houses) like other Monopoly Games, but it turned out that it was way more complicated than wr thought it would be. So here it is :
We chose to use this pattern in order to create Square cards more efficiently in our Monopoly Board. Unlike properties, cards are a like a dynamic object in this project whereas there isn't two similar properties on the board. Each time a player falls on a card square on the board (Chance Card or Community Chest), a random number is generated. Each number have a different action.
- UML Diagram
- Code :
This Factory Pattern enables us to instantiate Square very easily afterwards :
The choice of using a Singleton Pattern here ensures at any given point of time only one instance of the board is alive.
In this portion of code, the thread is locked (function lock) on a shared object and checks whether an instance has been created or not. Thanks to this code, we will take care of memory barrier issues and ensure that only one thread will create an instance.