Week 7 – Saving User Data
Welcome to my seventh Senior Project blog! This week, I worked on storing a player’s progress so that users won’t have to restart every time they close the game. I stored this data in a text file so that it could be saved when a user closes the game, and reloaded when a user opens the game again. Additionally, I worked on using my extra space to make the game look a bit nicer.
My original plan was to just store the user’s win-loss record, along with their last 5 games’ record. However after trying for a bit to write the code for this, I decided it would be easier to just keep track of every game’s result. I could go back through this text file in order to calculate the total wins and losses, and look at the end of the list to determine the last 5 games’ record. With this, I will also no longer need to delete lines in the text file, but can just keep adding forever. For example, if the user has a total of 8 wins and 5 losses, with their last 5 games being win, win, loss, win, loss, my text file might look like this:
To add a new game to this (a win, for example), I would need to update the text file to look like this:
To do this, however, I would need to write over the existing text file and either replace all the text on it, or replace it with a new text file. With my current way of tracking wins, I will now be able to have my text file look like this in the same scenario:
And another win would make it look like:
When loading the game, I would just need to read this in order to determine the information I need, and eventually be able to use this information to adjust the difficulty. So while this will take slightly longer to start the game if the text file has to be read, it shouldn’t be a noticeable difference, and will be much easier to keep track of while the program is running.
How To Make The Game Look Nicer.
Initially, my entire game screen was an 800×800 pixel board, with nothing else on it. I have since extended it outwards, giving me an extra 500×800 pixel space to include information and overall make the game look better. As of last week, I had added the total wins and losses onto the screen. This week, I added a count of the number of captured pieces on each side. A small red circle would represent a captured red piece, while a small black circle represents a captured black piece. This should let the player see how many total pieces are captured, as well as more easily compare which player has more pieces left, since the pieces captured are displayed right next to each other and the user no longer has to count the total pieces left.