Recreation of the game Monopoly using Java Swing in Java 11 for the CSC207 Fall 2022 Course Project at the University of Toronto.
Implemented with the Clean Architecture and SOLID design principles.
Includes save/load capabilities with serialization/deserialization of the GameState object.
- Ensure you are using Java 11. We built and tested this with AdoptOpenJDK Version 11.0.9
- Run the Main Method in Main.java.
After creating CRC cards to help identify the major classes required, a UML chart was made. This chart helps understand the relationship between the classes, interfaces and abstract classes. The chart also clearly differentiates between Entities, Use Cases, Interface Adapters and Frameworks/Drivers. After finishing the UML chart, implementation began.
The Tile Entities were the first elements to get implemented (two abstract
classes, one for Tile and one for Property and nine different tiles).
We made an inheritance hierarchy where each Tile Would be accessed through a generic Tile interface (primarily
the Tile.action()
) method
and each type of tile would implement the specific behavior and return a data object TileActionResultModel
with what
happened. During this phase
we also developed the other game entities (Player and Board).
After finishing the Tiles, the implementation of the Use Cases began (eight Use Cases each having their own input/output boundary interfaces). Each "Turn Use Case" corresponds to an action that the player can choose to take on their turn (ex. roll dice to move, mortgage properties). We use dependency injection here where each of the use cases implement their specific Use Case's InputBoundary and take in an OutputBoundary for their presenter.
The Turn Controller is the primary controller object that acts as a facade for all use case methods that need to be called with user inputs. We use dependency injection with the use case input boundaries here to keep the clean architecture.
Game State is an entity that contains the other Game Entities, handles Turn Order, and is the object that is saved when saving or loading a game.
UI classes define the Views for three different windows. We create a default/blank game view layout in the GameView class which is then modified by the presenters to have the appropriate text or buttons or other elements depending on the data passed to the presenters.
There are a few more classes that are not listed above, feel free to look at the JDocs for more information on these!
Shown below is the automatic test coverage generated by Intellij. We have tests for 100% of our Game Entities with a decreasing amount of tests as we get to outer layers in the clean architecture.
It appears the reason for the low test coverage percentage is that the UI Classes all have references to other classes and objects (Such as Java awt/Swing elements like JFrames, JPanels or other classes like TurnController which is present in every Presenter object). For instance, the game package does not have 34 classes in it (it has 5 + 2 interfaces) but Intellij is seeing 34. We also are not testing any of the visual elements as we can manually test those. Other than the UI, the complex (methods that are not getters/setters are not tested) are tested thoroughly thanks to more than one hundred tests.
Images in src/main/resources/assets created by Joshua @JLenander with additional modified Icons:
- Light Bulb Icon by Ferdizzimo on IconScout
- Railway icons created by Cuputo - Flaticon
- Chest icons created by Freepik - Flaticon
- Water Tap Icon by Elmira Gokoryan on IconScout
- Police badge Icon by Maxicons on IconScout
- Monopoly icons created by Smashicons - Flaticon
- Dollar-bill icons created by juicy_fish - Flaticon
- Dice icons created by vectorsmarket15 - Flaticon
- Jail icons created by Dreamstale - Flaticon
- Vessel icons created by Vectoricons - Flaticon
- Iron icons created by Freepik - Flaticon
- Sewing icons created by Freepik - Flaticon
- Car icons created by Freepik - Flaticon
- Shoes icons created by Izwar Muis - Flaticon
- Top-hat icons created by iconixar - Flaticon
- Dog icons created by Icongeek26 - Flaticon
- Wheelbarrow icons created by Freepik - Flaticon
- Monopoly icons created by Freepik - Flaticon