Background
I\'ve had problems for quite a while now with players cheating in my android game. For a strict single-player game this wouldn\'t be a big is
You can check periodically if your value has changed when it was not supposed to.
For example, you can store in a separate hidden flag the fact that the health value has changed. If your check method does detect a change in the value, and the flag is not set, then you can tell that the change was illegal.
For example :
void incrementHealth(int amount) {
health = health + amout;
hiddenCheck.hasChanged = true;
}
and in a separate method which must be invoked periodically :
void checkHealth() {
if (hiddenCheck.hasChanged) {
// change is valid
hiddenCheck.hasChanged = false;
hiddenCheck.lastKnownValue = health;
} else {
if (hiddenCheck.lastKnownValue != health) {
// An illegal change has occured ! Punish the hacker !
}
}
}
}