So basically the title sounds way fancier than the actual question.
I am writing an application in which I would like to implement an achievement system. If I have all of my achievements created as instances of a generic class, how do I write a method to validate those achievements (i.e. determine if the user has met or exceeded goals) when the type of feat accomplished may vary, the number of conditions to be met may vary and the type of validation may vary?
For example:
Achievement - 10,000 points!
Type - point total
Value (X) - 10,000
Conditions - 1
Validation - greater than X
vs.
Achievement - Ultra-frag
Type - kills
Value (X) - 10
Type - time
Value (Y) - 10 seconds
Conditions - 2
Validation - at least X in less than Y
I am trying to avoid hardcoding a validation function for every achievement since they are mainly generic and the only difference is how they are validated.
Like the achievement class looks something like
public class Achievement
{
boolean locked;
String name;
String desc;
public Achievement(string n, string d)
{
//ctor code
}
}
I am trying to think of a way to do this without function pointers and I am failing miserably. Also, can you even use function pointers in java? Im new to the language :(