Almost finished!
I've added the last of the gameplay features to the game this week. I had to cut the skills out of the game for now (things like Destroy, Uncover the map, etc) because there it is too much to implement in too short of a time. Even if I could get the foundation for them implemented, I fear that I could never get it debugged and balanced before the deadline. I replaced the Skills with upgrades for the Big Alien, which were much easier to implement since they are very similar to the upgrades for the Small Alien that were already implemented.
I added the fourth faction to the game, the Builders. I was not sure that I would be able to finish them, but I decided to make them pacifists, so I didn't need to write all of the code to allow their ships to attack and be attacked. They simply spawn a ship when they have enough resources, and that ship captures the target planet in one shot.
The cool thing about the Builders is that they produce Relics while they control a planet. You can destroy them early in order to prevent them growing too big to manage, but if you wait to wipe them out, you will gain lots more relics. The Fighter faction also sometimes attacks them, so the player may want to defend them to farm more relics. Relics are used to purchase upgrades for the Big Aliens.
Manual Save And Loading
I'm not sure if anyone else uses this approach, but I always like to write methods to manually save the data necessary to recreate the game state. I know that it is possible to use libraries for easier serialization, but the resulting file sizes are much larger. Also, when you write methods to save only the essential information to file, you often find problems in the structure or design of your code that will be beneficial to solve, and become necessary to solve in order to save and recreate the game objects.
Here is an example of how I do this, with the Star class.
First, I write a method that returns a string that contains all of the information necessary to recreate a Star.
The BZStringTools class contains some members and methods that make it easier to save things in strings. The lineDelimiter (an "=" string) is used to separate the larger parts of the data, while the delimiter (a "-" string) is used to separate the larger parts into their smaller parts.
When I need to save, the save() method of the MainGame class is called. It calls the saveStars() method, and writes out all of the information to a file.
Here is the contents of that file:
Then when loading, the MainGame class calls the loadStars() method, which loads up the file, splits the contents, and recreates the stars.
When loading, the MainGame calls this static factory method of the Star class:
The unfortunate consequence of doing things this way is that I need to know what the order of the string elements will be (the order they were appended in the getSaveString() method). Any small mistake will result in errors in parsing and crashes.
After parsing the string, a special constructor is called that is only used when loading Stars:
And that's it! I still need to write methods for about 60% of the game, but everything will follow this same basic pattern. Saving is not super important for my game, but I would still like to allow the player to save and continue.