Indeed, there are tools out there that will automatically generate classes such as this one. These tools are often called "4th generation languages". Unfortunatly, we don't have a 4th generation language here, so we will have to do this by hand.
| DeedSpace |
|
| FreeSpace |
![]() |
| GotoJailSpace |
![]() |
| JailSpace |
![]() |
| GoSpace |
![]() |
| TaxSpace |
|
| ChanceSpace |
|
| ChestSpace |
|
One space is missing in this list: the jail itself. Since the rules for entering and leaving the jail are different from every other space, we will use a different implementation.
In this change, you will be given Space.h, which is once again an (almost) pure abstract class. To make debugging easier, I predefined some virtual functions, but later, these definitions can be eliminated.
You will have to create two files: SpaceTypes.h and SpaceTypes.C. As usual, looking at the tests can provide helpful hints. Note how we are using the game.data file to create our initial environment for the pointer types.
Since the board is cyclic, we will store the spaces in a special index
called SpaceLoop. We will redefine the next() and
prev() functions to simply ignore the end of the list and
jump right back to the beginning. We will also allow a numeric
argument. Things can happen to a player when passing through a space or when ending on a space. We will provide two virtual functions for these two cases. For the time being, we will leave those functions untouched, but later, once we have all the monopoly objects set up, we will fill these functions with meaningful code.
In this change, you will need to create a Space.C to implement the next() and prev() functions defined in Space.h. You also should implement SpaceLoop.C according to the given SpaceLoop.h. Finally, You will need to add a data element spaces to the Game object and get the newest game.data file As usual, looking at the tests can provide helpful hints.
Note that since we aren't moving the spaces around and never keeping a list of spaces, we do not need a space pointer list class.
Since we are changing previously tested data objects, the old tests will no longer compile properly, let alone work properly, so we might as well aerm them.
As usual, a new game.data file is there, and looking at the tests can provide helpful hints.