Skip to content

2. Architecture

Tomás edited this page Jun 21, 2020 · 2 revisions

General view of the architecture of the project This diagram represents a simplified overview of the structure of the code. For the sake of clarity, we will explain each part individually.

World, Locations & Actions

The World class (singleton pattern) holds a list of Locations (currently there are: House, Office, Bank, Park and Bar). Also it implements the LocationChanger interface that allows players to move to other locations (explained in the Façade Pattern section)

Each Location holds a list of Actions that can be performed there, as well as a list of Actions to go to other locations (moveActions). This will be explained in detail in the Command Pattern section under the Patterns page.

Players

Fields of the player class

There's a general Player class that encompass the behaviour of every player. It has a reference to the market (singleton pattern), a signal for mentalHealth and Hunger, a reference to their current Location, and a LocationChanger to move to other locations. Also they have a personal signal of Time for events purposes.

Two classes extends it:

  • Broker: the class for the actual player of the game. Every decision (what to buy, where to go...) is decided based on the input gotten through the console.
  • Bot: the class for the non-player characters. They can do the same set of actions as the player, but the decision making is based on algorithms. This will be explain in detail in the State pattern section on the Patterns page.

Market & Asset

The Market is essentially a list of Assets that can be bought/sold/etc by the players.

Every Asset has several attributes. The most relevant is the AssetState which determines how the price of the asset varies with time (i.e. bankrupt, etc)

Events & Time

The whole game is ruled by Events. The previously mentioned Actions are performed inside Events. They are also used for other types of tasks.

The game has a global signal of Time, that advance with every actions of the player. Each Event has an assigned trigger time.

The game has an EventHandler, which is in charge of triggering the execution of the list of pending events, once the Game's time matches the event's trigger time.

Broker/Bot Update Event

These are the most relevant types of Events in the game.

When a player decides to perform an action (either by typing it on the console or deciding it with an algorithm), the action itself is wrapped in an event, whose TriggerTime = the current time + duration of the action. When the moment arrives, the EventHandler is in charge of calling the perform() method of the action.

Here's a sequence diagram representing the process for a Broker (with console input).

Clone this wiki locally