Question: Objective Create a struct in order to store settings for the application Instructions In order to allow the Game of Life to be customized, it
Objective
Create a struct in order to store settings for the application
Instructions
In order to allow the Game of Life to be customized, it will be necessary to keep track of a few different settings. A couple of these settings already have values that are being tracked in the program. Creating an object for the settings will make it easier to pass around the program from object to object.
Create a struct that for the game settings in a new header file. No need for a cpp file in this case. At a minimum, the struct will need to track the following pieces of data for now.
The color of living cells, stored as unsigned ints representing the Red, Blue, Green, and Alpha values. Default the RGB values to and the Alpha to
The color of dead cells, stored as unsigned ints representing the Red, Blue, Green, and Alpha values. Default the RGB values to and the Alpha to
It is possible to run into Read Access errors if trying to read a wxColor that has been loaded from file. This is because one of the classes the wxColor inherits from does not like being written to directly. In order to get around this error, don't store wxColor directly. Instead store the Red, Green, Blue, and Alpha values as unsigned ints. wxColor has GetRedGetGreenGetBlue and GetAlpha methods that can be used. It may make sense to create a method in the Settings struct that returns a wxColor based on the specific RGBA values that are stored.
The grid size Default to
The interval Default to
Eventually information about the window size and location may be added to this struct, as well as other any other options that can be tracked.
It may make sense to add methods for getting the living cell color and getting the dead cell color that returns a wxColor. Creating setters for living cell color and dead cell color would make sense too. Those could take in a wxColor and set the RGBA values from those colors.
Add a variable to the main window header for the settings object. This should not be a pointer.
Since the grid size will now be tracked in the settings object, it will be necessary to remove all existing references to that variable and replace them with the reference to the settings object.
The easiest way to do this is to removethe size variable from the main window header file.
The cpp file will have many errors at this point. Each error can be fixed by referencing the appropriate variable in the settings file.
Now that there is a settings object, this can be used to pass data to the drawing panel. Create a settings pointer in the drawing panel header file.
The value of the settings object pointer can either be set in the drawing panel constructor or through a setter. The easiest way is likely to create a setter for the settings pointer.
It will again be necessary to remove all existing references to variables in the drawing panel and replace them with the reference to the settings object pointer.
To test, change the default values in the settings object file and open the program. The interval, grid size, and colors should change based on the default values.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
