I’m coding an archievement system as it follows:
IAchievement – Interface that all achievements must implement
AchievementManager – Class that with a user id checks for all achievements
My idea was to have a shared function on ArchivementManager as I could performe something like
AchievementManager.checkUser(userId)
Or
AchievementManager.check(userId, achievementId)
Anyhow the AchivementManager should call a function check for each IAchievement implementation.
As it does not make any sense to have an instance for each Achievement I’m checking I was expecting to be able to declare the check method as Shared / Static. So inside the AchievementManager I could just call for
AchivementXXX.check(userId)
But I can’t declare shared functions in my interface.
Is there any workaround? It is a bad aproach to inmplement an achievement system?
Edit:
This is not for a game but a website in ASP.NET
If your approach is to define an interface, then yes it would make sense to have the AchievementManager hold an instance of each relevant achievement type.
This also makes sense because one would expect the achievement instances to need to exist, for example in order to track various game state and listen to various game events so that they can detect that the achievement has been achieved. Otherwise, how would achievements implement their Check method?