Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
cant find a pattern to fit neatly - how to make a large number of monsters?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="thufir, post: 598388"] If each monsters attributes are composed of different objects, it should be very easy make a SuperSword class and have bigMonster.armWith("superSword") I'd think. I don't know how to address your codebase size concern, sorry... instead of a list of abilities, try for objects :) As in a sword object, or fireResistant object, of which a particular Monster type object would be composed. That is, each object would "have-a" object, or objects :) Composition works very well at encapsulating data, which allows you to change dependant classes to a larger degree. public class BunchOfMonsters { public static void main (String args[]) { Creature blobMonster = new Monster("blob"); //"blob" is a monster type blobMonster.armWith("sword"); //sword is a type of weapon //have a list of monsters } } public class Monster implements Creature { public void armWith(String wep){ if (wep == "sword") { Item aSword = new Sword(); } //give sword to monster instance //Sword implements Item } public void attack() { // find best weapon // find target } } how about each instance of Monster has an instance of Melee? Using Timer() each melee object determines when it gets to move. This object would then determine whether to fight or flee? <[URL]http://robocode.alphaworks.ibm.com/home/home.html[/URL]> AFAIK this uses a "tick" idea, where there's a list of 'bots which gets iterated through once/sec; this is less complex than having a Melee class. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
cant find a pattern to fit neatly - how to make a large number of monsters?
Top