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="stevenmathers, post: 598517"] I see people can tell where Im coming from with this. It really helps to have someone else state the problem and solution in different language. Finally I think I can define the problem in a clear way: A monster has characteristics which are _common_ to all monsters, such as Speed or the ability to resist certain types of damage, even if that resistance is 0. These simple characteristics are represented as attributes in the class Monster. A monster has optional characteristics and/or behaviour which is represented by a list of Abilities. A sword ability, a resistance to fire ability of +50%, a wand of Increase Speed, etc... Adding new monsters is easy, you just create a monster with a different name, different values for its characteristics and give it a different starting set of abilities. The most important thing with this design is to make the definition of new abilities as easy as possible. I want a code-efficient, elegant way to define a new ability - the more abilities I have, the more different types of monsters I can easilly create. Of secondary importance is the impact of defining new characteristics. Whenever a new characteristic is defined, or a new ability defined, it must not change the interface between Monster and Ability. Thats a maintainance nightmare. I propose to use something like the Command Pattern between Monster and Ability. Monster creates a command such as 'modify this speed attribute', sends it to all its abilities, and those abilities may or may not satisfy the request. So when I define a new ability, I just have to define the command it responds to, and also the response itself. I think broadly there are three types of response an ability can have: 1) modify a value passed in (i.e. yes, I modify speed, and here is your modified speed result) 2) perform a function and return the result (i.e: 'yes, I am your currently wielded melee weapon, and I do 10 physical damage') 3) apply an ability to a target Monster. i.e a wand of increase speed gives the Monster the ability to apply an 'increase speed' ability to a target Monster. so... to fully define a new type of ability, I need to define the strategy by which it is invoked (largely a GUI strategy issue), and/or the command it responds to, and the strategy it applies apon either being invoked or receiving that command. So I propose to use a type of strategy pattern to implement the response of an ability to a request. that way I can define new abilities in one table, and have a factory create them using the table ID. i.e. ability #5 name: "increase speed effect" invoking strategy: NONE command: SPEED_MODFIY execute strategy: VALUE_MODIFIER execute param: +50% ability #6 name: " wand of speed" invoking strategy: AQUIRE_TARGET command: NONE execute strategy: ADD_ABILITY execute param: ability #5 and so on... I think its reasonable, but id be glad to hear otherwise [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
cant find a pattern to fit neatly - how to make a large number of monsters?
Top