cooperuser / blockade

A minimal but challenging puzzle game, inspired by the ice puzzles in The Legend of Zelda: Twilight Princess.
2 stars 0 forks source link

Saving user progress (and Level IDs) #28

Closed grady404 closed 7 years ago

grady404 commented 8 years ago

Saving the user's progress will require a bit of an overhaul/update to the way levels are saved. Each level would be associated with a specific progress file, which would contain information about the player's best scores for moves, distance, and time (the file would not state whether or not the level has been completed, as the existence of the file itself would signify that the level was beaten). This would be saved in a completely different directory than the level files themselves, so that save data can easily be backed up. I'll go over a few potential ways to implement this system and highlight their flaws before presenting what I believe should be the final version of the progress system.

The first and most obvious idea would be to name the progress files level1, level2, etc. to match the names of the actual level files. But a problem clearly arises if the level files themselves are reordered (and thus renamed) to make way for new levels or simply to change the order that the existing levels appear in the game. Then every time this happens, the progress files would correspond to the wrong levels. Another thing you could try instead would be to associate the progress files with the name of the level, but then if you rename any of the levels, the same sort of thing happens.

So here's my suggestion: give each level a unique Level ID (in the .json file), and make the progress files correspond with the Level IDs. That way it doesn't matter if the level is reassigned a new level number, or given a new name, the user's progress will still persist since Level IDs never change. There are a couple of ways you could do this:

EDIT: Ignore this next paragraph, see #58 instead.

So how would you actually go about giving each level a unique Level ID? If you just generated an ID randomly for each level, there's always the chance (which increases the more levels/users the game has) that two will coincide, causing two levels to have the same ID. You could set up a server to generate all the Level IDs, and that way you could make sure the same ID is never used twice, but that would require an Internet connection any time someone wanted to create a level, and would generally be really clunky. So here's a solution I came up with using a bit of ingenuity: find some number which is completely unique to the user's computer (serial number, MAC address, or something like that, but ideally something that wouldn't be considered private or personal information) and the time on the system's clock (as precise as you can get), and create a unique resultant number out of those two values. I would recommend you multiply the system's address by [the maximum value for the system time plus one], then add the system time. Then put it through some sort of password hashing algorithm for encryption, so the user can't meddle with it. That way, Level IDs will always be unique, and you don't need to set up some server to manage them.

Yeah, I know this post was pretty long, but hopefully you'll find a way to implement this nicely (and soon) so players can start tracking their progress in the game.

grady404 commented 8 years ago

Shit, I just realized that multiplying two numbers (for the Level ID generator) doesn't always give a unique result. Idk what I was thinking. I will update the post.

cooperuser commented 8 years ago

Okay

grady404 commented 7 years ago

While level IDs are not yet completely implemented, a save system was added to the game in version 0.4.0. See issue #58 regarding level IDs.