Giter VIP home page Giter VIP logo

monopoly-game-in-csharp's Introduction

Final Project : Design Pattern - Monopoly Game in C#

Justine LAGRANGE & Yann KERVELLA

SUMMARY

Project Overview

image

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 !

What Monopoly functionalities we have implemented

  • 2-6 players

image

  • Random Dice Rolling

image

  • 40 Square Board

  • All properties implemented with options to buy, add house and add hotels to increase future revenues

image

  • Chances Cards and Community_Chest Cards implemented with random events : earn money, pay taxes, move backwards or forwards...

image

  • Jail option added

image image

  • 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

image

  • Dashboard option to see our information

image

  • Game Status Option

image

The Decorator Design Pattern

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 :

image

image

The Factory Design Pattern

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

image

  • Code :

image

image

image

image

This Factory Pattern enables us to instantiate Square very easily afterwards :

image

image

The Singleton Design Pattern

The choice of using a Singleton Pattern here ensures at any given point of time only one instance of the board is alive.

image

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.

monopoly-game-in-csharp's People

Contributors

sushifou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.