Skip to content

chlotmpo/DP_Final_Project_Monopoly

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Monopoly Game in C#

Monopoly is a real-estate board game for two to eight players. The player's goal is to remain financially solvent while forcing opponents into bankruptcy by buying and developing pieces of property. Bankruptcy results in elimination from the game. We implemented a simplified version of monopoly in C#, through common software development practices. The rest of this document details the implementation of our project.

Team

This project was realised by Chloé TEMPO and Matthieu THIBAUT

Table of Content

  1. Design Implementation
  2. UML and Sequence diagrams
  3. Sequence of the game

Design Implementation

During the analysis of the subject and the problems that could be encountered, we determined 3 situations for which the implementation of a design pattern proved to be relevant.

Singleton Pattern

Situation / Problem: As part of a monopoly game, there are several players but a single game board on which all the players play their turn. In our programm C#, we must therefore ensure that only one game board will be created since all players in a game have to play n the same one.

Solution : The singleton pattern is a software design pattern that restricts the instantiation of a class to one « single » instance. This is useful when exactly one object is needed to coordinate actions accross the system. So we decided to implement the singleton pattern in a class called "BoardSingleton" which corresponds to the game board object.

image

Factory Pattern

Situation / Problem : The monopoly game board consists of 40 cells, each of which is different. These boxes are grouped into 6 different types. Properties, chance cells, community chest cells, jail, tax cells and other special cells. All cells are characterized by a position in the board but have different properties, methods and behaviors.

Solution : The factory method pattern is a creational pattern that uses factory methods to deal with the problem of creating objects without having to specify the exact class of the object that will be created. This is done by creating objects by calling a factory method—either specified in an interface and implemented by child classes, or implemented in a base class and optionally overridden by derived classes—rather than by calling a constructor.

We decided to implement this factory pattern by creating an interface "ICell" from which derives the classes "Property", "Chance", "CommunityChest", "Jail", "Tax" and " Special" then by creating an abstract class "CellCreator" which will lead to the creation of the cells according to their types (the latter being defined in an enumeration) and a class "CellFactory", which derives from the abstract class and which creates the objects corresponding to the types of the cells.

image

Observer Pattern

Situation / Problem : One of the hallmarks of monopoly is buying properties. When a player arrives on a property square, if it’s available, he can then buy it and become the owner. Players should therefore be aware when properties are purchased by a player and know that they will have to pay if they pass by.

Solution : The observer pattern is a software design pattern in which an object, named the subject, maintains a list of its dependents, called observers, and notifies them automatically of any state changes, usually by calling one of their methods.

So we decided to implement this design pattern to inform all players who wait their turn as soon as a player has bought a property. They are therefore aware of the situation and know that his property is no longer for sale and that they will have to pay a debt on the spot. We implemented an abstract class "Abstract Observer", from which derives the class "Player", the players are the observers. The "Property" class has a list of observers in attributes (which corresponds to all the players in the game) and methods to define when to warn the observers.

image

UML diagrams

Class Diagram

Here is the UML class diagram of the solution, it is completed with the design patterns seen above. The aim Program class, which represent a game, is to run the Monopoly.

image

In addition to that, we have a class named Program that contains all the needed methods to run the entire game.

image

Sequence Diagram

We decided to represent a simple use case : Buying a property. In this sequence diagram you can follow the différents steps to acquire a property and the interactions between the user and the program through the console interface.

image

Sequence of the game

Here is a demonstration of a monopoly game for 4 players from our solution.

When you launch the program, the following window opens : We press « Y » to play. We will then have to choose the number of players and their names.

image

image image

PLAYER TURN : Now the game is initialized. Now the players’ turn will begin. Here is how a typical turn is played for a player. The player rolls the dice and advanced the number of corresponding cells.

image

If the player has not made a doubled dice, his turn ends. Otherwise, he plays again. After 3 doubled dice in a row, he goes to prison

Message when the player made a doubled dice :

image

Message when the player made 3 doubled dice in a row :

image

If the player lands on a PROPERTY CELL : The property informations are presented to the player. The player decides whether to buy it or not. The program then verifies that it has enough money and, if necessary, the property is sold and belongs to him.

image

A message is then sent to all observers (players).

image

If the player lands on a CHANCE CELL or a COMMUNITY CHEST CELL : A random number is then generated. The program then displays the corresponding message. These cards can bring money, take it out, take the player to jail, get the player out of jail, or do nothing.

image

image

If the player lands on the JAIL CELL : He is simply visiting the prison. The program displays the current situation of the jail, if some players are in it or not.

image

If the player lands on the GO TO JAIL CELL : He goes immediatly to jail.

image

At the end of each turn, the players’ situation is displayed.

image

SPECIAL SITUATIONS :

When a player IS IN JAIL : He’s going to roll the dice when it’s his turn. If he gets a double, then he can get out. Otherwise, he doesn’t move forward and is patient in prison. After 3 truns without doubles, he goes out in any case.

image

When a player OWNED SEVERAL RAILROADS : If a player arrives at a railroad already purchased by a player and the latter has several railroads then the amount to be paid will be multiplied by the number of stations owned.

image

When a player OWNED ALL THE PROPERTIES OF THE SAME FAMILY : If a player has all the properties of the same color or all the companies then if a player passes on one of these properties, the price to pay will be doubled.

image

A PLAYER LOSES : A player loses the game when he does not have enough money to pay another player, or a cell on which he landed. He is then removed from the game and all the properties he bought are put back into the game.

image

WIN THE GAME: To win the game, one player muste have ruined all the others. When all the others have no more money and he is the last player to compete, he is then declared the winner. The following message appears in the console. The game is over.

image

About

🎲 Monopoly Game in C#

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages