3
\$\begingroup\$

I know this would be a beginners question (some of you might think) but I would like to know different approaches for this.

I have a game with lets say 20 unlockable items, at the main menu I have a button where the user can go to an activity and view the unlockable items. So I would like for it to have a "Locked image" and under it a text telling you what the item is and maybe how to unlock it.

What is the best way of going about this?

And then when the item is unlocked during the game, maybe put a variable in the shared preference and check at the beginning of the activity with the unlockabled items.

Let me know what you guys think. Thanks.

\$\endgroup\$
3
  • \$\begingroup\$ I too would be interested in how different people do this. Would the unlockable content be downloaded or included with the app? That could make a difference piracy wise if players were paying to unlock. If they are just achievements, I would be tempted to go with a little SQLite db \$\endgroup\$ Commented Jan 12, 2012 at 11:26
  • 4
    \$\begingroup\$ What do you want to know? How to make an item be unlocked when you do something, or how to store the item requirements to be unlocked on the device? \$\endgroup\$ Commented Mar 22, 2012 at 1:36
  • \$\begingroup\$ Your question seems a bit vague. \$\endgroup\$
    – notlesh
    Commented Mar 22, 2012 at 20:59

2 Answers 2

2
\$\begingroup\$

Knytt Stories and Spelunky do this:

They store records and unlockables in an unencrypted text file. To prevent curious people (who like to read random text files) from accidentally spoiling the game for themselves, it only adds things to the text file once the player encounters them. The file has lines such as SpidersKilled=2, but only if the player has already killed a Spider. The line not existing means as if it had said SpidersKilled=0.

This makes it possible for players who want to cheat to do so, but protects innocent curious cats from getting their tails burnt.

\$\endgroup\$
-1
\$\begingroup\$

Disclaimer: I don't have any experience in doing this, but intuitively, this is how I would consider doing it.

Firstly, in regard to @SpoonThumb's comment, I'd include the unlockable items in the game from the start.

Secondly, I'd store which items they'd unlocked as SharedPreferences on the phone, but with some form of encryption before they are saved. The encryption key would be inside your code, and then you may be able to obfuscate this code. It doesn't make it tamper-proof, but it would make it harder for someone who wanted to tamper with it.

You may consider storing the things they've unlocked on a server somewhere, but I get annoyed when games do this, because I can't play them properly when I am offline. Perhaps a middle ground would be to do both, and whenever they are connected to the server, just check that they haven't tampered with their unlocked items. For example, let them do whatever they want on their phone, but as soon as they try to submit a high score, perhaps you could check if the preferences on the phone are the same as those on the server.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Oh, and I've seen people suggest to base64 encode your preferences to make them harder to tamper with. Please don't do this. Yes, it is harder for the layman, but it is just as easy to modify as plain text for anyone with any sort of tech knowledge. If you're going to base64 the preferences, may as well just encrypt them. That requires decompiling the code to get at the encryption key. \$\endgroup\$ Commented Mar 22, 2012 at 0:50
  • 1
    \$\begingroup\$ -1 it's single player, you shouldn't care if the user wants to mess stuff up. \$\endgroup\$
    – o0'.
    Commented Mar 22, 2012 at 10:58
  • \$\begingroup\$ I didn't see where it was specified that it was single player. However, single player games may still have global high score tables. Also, if it only takes one or two lines of code, and virtually no processing time, you may as well encrypt the preferences. \$\endgroup\$ Commented Mar 22, 2012 at 23:56
  • \$\begingroup\$ Client-side encryption won't help to prevent cheating, the high score would be hacked anyway. I won't explain in a comment why, just search around, myself and other have explained that plenty of times already. \$\endgroup\$
    – o0'.
    Commented Mar 23, 2012 at 0:07
  • \$\begingroup\$ I agree with what you say in that everything will be hacked by someone determined enough. But I suppose I was thinking more along the lines of: gamedev.stackexchange.com/questions/23296/…, I guess I was looking at casual users opening up a text file and changing a number. So if there was a global high score system, people who hack the preferences to unlock items will have a better chance at getting a higher score, therefore cheating. \$\endgroup\$ Commented Mar 24, 2012 at 11:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .