I understand that for more complex achievements, specific code can't be avoided, but for simple ones like (player clicked 100 times) or (player earned 30 bajillion cookies) or (player played for 1 hour) it should be as simple as abstracting the achievements to something like a list of properties/values and having some event handler.
My problem is that since I'm using Javascript and there's no really clean way to do pointers, how am I supposed to create an achievement class that can be iterated through procedurally?
Ideally I'd like something like this:
Achievement class:
function Achievement(name, property, value, text, points){
this.name = name;
this.property = property;
this.value = value;
this.text = text;
}
And then I'd add an achievement like so:
achievements.push(new Achievement("Clicktastic", &numClicks, 1000, "You clicked 1000 times!");
And have some kind of function bound to a Window.setInterval that was constantly looping through all achievements and for these simple types doing something like:
for (var i = 0; i < achievements.length; i++){
if (*achievements[i].property >= achievements[i].value){
//deal with earning achievement
}
}
I'm just using some C style pointer/dereferencing notation here.
Basic idea is that I'm not sure how to create a generic achievement that can arbitrarily care about specific properties without pointers.