Amend the code provided in answer to the previous assessment as follows. Remember that practicing your capacity for decision-making when confronted with ambiguity is important to your development. However, careful reading would help.
Add appropriate getters and setters to the Element base class. You do not need getters or setters for the RandomNumber and Console attributes, they are set in the constructor. Derive Flotsam and Jetsam classes from the Element class. Make the Element’s printAt method pure virtual and have two versions of it, one for each derived class. The difference is simple. Flotsam outputs black as the foreground and Jetsam outputs white as the foreground. Remember that a derived class constructor needs all the parameters that the base class requires. For simplicity, the has-a attributes are protected, not private.
Now for the harder part, provide a class called Board.
The class must have the following attributes:
• a RandomNumber object;
• a Console object;
• a container for holding up to 20 Element pointers, which will hold flotsams and jetsams; and
• an integer called tick that counts the iterations
The Board class should have the following behaviour, but you can extend it to gain higher marks.
Board() : a constructor that populates the Element container with ten flotsam and ten jetsam as well as initializing the tick counter.
display() : a method that displays all objects at their current x, y coordinate by calling each object’s printAt() method.
void loop() : this is where object coordinates will be updated appropriately and identifiers displayed. You can add additional functionality, such as dealing with collisions, if you want to earn a very high mark. The following design should help.
while tick < 100
output current tick
for all elements that move this cycle
overwrite current coordinates with a space
redraw object at new coordinates
void moveObjects() : for each object, call adjust their coordinates appropriately if tick % (11-speed) == 0. (Hint: degrees greater than 338 and less than 22 would be north.)