This site requires JavaScript, please enable it in your browser!
Greenfoot back
Juicyz
Juicyz wrote ...

2014/8/26

Best way to implement cooldown system

Juicyz Juicyz

2014/8/26

#
I'm creating a mini RPG and not 100% where it is going to go. Just making things as I think of them currently. Lately I've been thinking about how to implement cooldowns for spells. The spells are created inside XML which I parse and store once the game starts up. Normally if there is a small list I would make variables and variable timers for each but this would be a mess when I expand to having more spells. My other option that I have been thinking about is using a ConcurrentHashMap or ConcurrentSkipListMap then when a spell is cast, put the name of the spell inside the map and schedule a runnable that would remove the name after the specific cooldown time. Would my second option be the best way to go about it or is there another solution?
danpost danpost

2014/8/26

#
I think it would be easier to just create a 'Spell' class that each spell, with its own class, can be placed under. The Spell class can provide the cooldown functionality and the fields, plus any other common members; the individual spell classes can set their specific values for the fields and implement their specific behaviors. If you are trying to conserve on project size, you can give each spell an identification number and use switch statements to work out each part of the spell in the Spell class and dispense with the individual spell classes.
Juicyz Juicyz

2014/8/26

#
I might try that. That would normally be how I would do it following the OO design but I really hate how greenfoot doesn't allow packages. All the code goes in one huge place so I'm trying to keep it semi-neat and tidy. Though doing it that way I can remove the XML since it will be all in code. Currently the way spells work is that I have a Spell class that holds all the characteristics of the spells and all the spells are in a list. When a player casts a spell, it creates a SpellObject and it inherits the spell characteristics. Then the SpellObject has an act method that handles every kind of spell that I can make. Basically it just moves the spell according to what I set it in the xml and has different effects also declared the xml. The effects are "hardcoded" but that list is a smaller list because all the spells can use them. It is a pretty generic system that allows all new added spells to be just in xml instead of adding more code code and classes.
You need to login to post a reply.