• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] Dynamic Objects - Robot Example

This topic is 6238 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Problem. I have a bunch of robots that have different behaviors, attributes and skills. At the moment all robot types are predefined, but I would really like to assemble a custom robot on the fly.
consider this:
class LargeRobot extends MotherRobot implements Infravision, Flight, Turbo, Kick, Hostile

Next time around I want to create a LargeRobot that doesn''t have Flight but has Dive instead. How do I make this structure more dynamic? Would it be smarter to let LargeRobot have a vector of behaviors, attributes and skills that can shrink and grow? How would a smart java game programmer solve this basic task?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
the design patterns forum has a thread on this very same topic, check all the threads and see if you can find it. They are using spaceships as their example. Or if you are looking for a simple solution just include all the abilities and then have boolean variables for whether they have the ability. Then if the ability is true, the method works normally, otherwise it does nothing.

Share this post


Link to post
Share on other sites
quote:
Or if you are looking for a simple solution just include all the abilities and then
have boolean variables for whether they have the ability. Then if the ability is true, the method works normally,
otherwise it does nothing.


That would work but it sounds like I''ll end up with 5000 if then statements to check all the boolean variables? And the class will be extremely large and waste memory space if a third of all the functions are not used?

Share this post


Link to post
Share on other sites

  • Advertisement