Reputation: 51
I'm honestly new to game dev and android. As of now I'm working on a game that goes like a virtual pet game were a "Game World Time" is involved. You know, where the player quits and then resumes playing after several hours and then a progress during that time occurs. How should that be properly done? If I use the system time as reference, that'd mean the user can cheat the game by adjusting the time right? Hoping someone would give me the gist of how these kind of games work. Thanks in advance!
Upvotes: 2
Views: 1035
Reputation: 8101
You are absolutely correct. One could cheat by setting the internal clock to something different. There are workarounds though.
Using System.currentTimeMillis()
is most likely cheatable by setting the clock. Using SystemClock will only be even harder to implement, because what if the user suddenly reboots the phone? Then it'll look even more like hacks.
You could use a ntp server to get a timestamp from that or you could use GPS time from the LocationManager, but the best solution by far is that you set up your own server, that acts like a webservice, which also provides timestamps.
Upvotes: 1
Reputation: 24174
You can use SystemClock#elapsedRealtime()
(or SystemClock#uptimeMillis()
, whichever is appropriate). I'm not sure there is a way to cheat in this implementation.
Upvotes: 0