Previous Exercise | Next Exercise | Lecture | Top Level

Deeds

Context

This week, we will implement our first real life monopoly object. We will start with the deeds, those ownership certificates that entitle you to claim rent whenever an opponent lands on the space associated with the deed.

cards

There are three kinds of deeds: properties, utilites and stations. All deeds allow you to claim rent. The amount of rent is a function of how many other deeds you have that belong to the same group. Properties come in different colors, every color indicating a group. Stations and utilites can be considered as one group each.

Deeds have a price and a mortgage value. You may obtain a loan from the bank for the mortgage value, but doing this precludes you from claiming rent. We therefore need an mortgaged flag.

Finally, deeds belong to someone. Since we haven't defined the Player class yet, we will use Key as a placeholder class until we are ready for the real thing.

These are all properties common to all kinds of deeds. We will therefore use a base class Deed to represent all those common properties.

The individual particularities of every kind of deed will be implemented in the derived classes PropertyDeed, UtilityDeed and StationDeed.

Since there is a lot of data associated with every Deed, we will use pointers to refer to other deeds. Therefore, we need to derive Deed from Indexable. We will then derive DeedPtr from Pointer, and finally, create a list of pointers called DeedPtrList to refer to all the other deeds in the same group.

The DeedIndex in which all the deeds are stored will contain elements of different classes. We will therefore have to implement a smarter readContents function for this class.

This is the entity relationship diagram of class hierarchy we are creating:

erd

Exercises

Change 12
Create class stubs for Deed, PropertyDeed, UtilityDeed and StationDeed, all sitting nice an cozy in their own (very short) files. Just implement the minimal set of required functions. Use the inheritance tree depicted in the entity relationship diagram above. Note that the aenf command will create a template that is quite close to a workable stub. Try to delete as much as possible from those templates and keep only the minimal set of functions to make the class work (Hint: implementing the virtual functions defined in higher level classes is enough).

The existance of those class stubs will allow us to derive DeedIndex from Index. This is actually quite simple: you only need to redesign the readContents function to enable it to read the three different kinds of deeds, as the Index::writeContents function already works.

As usual, DeedIndex.h is provided... and looking at the tests can never hurt...

Finally, add the data member DeedIndex deeds to the Game class. Update Game::ReadContents and Game::writeContents, making sure you check the returncodes. Remove the Account data member but keep the Dice data member - you will need it for change 16.

This change looks like a lot of work, but it really isn't. It is required to finish this change before you can work on any other changes in this exercise.

Change 13
Fill in the Deed class stub, and add the DeedPtr and DeedPtrList classes. They will all share the same file. As usual, Deed.h is provided and you should write Deed.C... and look at the tests!

Note the monopoly() member function returns GroupSize defined in Base.h. Note that the value all means that all group members belong to the same player, and that the values one, two and three may only be used if there is at least one group member which doesn't belong to the same player. This is because two property groups have only two members, whereas all other property groups have 3 members. It is important for determining the rent to know if all properties of the same group belong to the same player.

Once again, this change needs to be finished before the next three changes can be compiled. Once this is finished, though, the next three changes can be done simultanously

Change 14
Using PropertyDeed.h, implement PropertyDeed.C. You will need to add the data required for calculating the rent. The rent of a property depends on the number of houses on that property, or, if there are no houses, on wether the owner owns all properties in the same group (in which case the rent for no houses is doubled).

Use the data type Houses defined in Base.h to index an array of rent amounts. When reading or writing that array, first read/write the index of type Houses, then read/write the rent amount. A look at the tests will reveal more on the expected data formats.

Later, we will implement the member function build(). Since this function requires monopoly objects we haven't defined yet, we cannot implement it properly. We will therefore leave it as an empty "stub".

Change 15
Using StationDeed.h, implement StationDeed.C. You will need to add the data required for calculating the rent. The rent of a station depends on the number of stations owned by the same player. Use the data type GroupSize defined in Base.h to index an array of rent amounts. When reading or writing that array, first read/write the index of type GroupSize, then read/write the rent amount. A look at the tests will reveal more on the expected data formats.

Change 16
Using UtilityDeed.h, implement UtilityDeed.C. You will need to add the data required for calculating the rent. The rent of a utility depends on the number of utilitys owned by the same player and the current die roll. Use the data type GroupSize defined in Base.h to index an array of factors with which the die roll is to be multiplied with. When reading or writing that array, first read/write the index of type GroupSize, then read/write the factor. A look at the tests will reveal more on the expected data formats.


Christian Goetze