Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Need help with a RPG battle engine...  RSS feed

 
Ben Cramphorn
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically I am working on a simple battle engine... this is just my first attempt at making any type of game and arn't really aiming to make a RPG just trying to see how much knowledge I have and make as good a battle system as I can.

All the enemies I have made using objects... such as bat, troll etc... and they have attributes such as hit points.. experience points left after dead... attack and defense power...

anyway to start my battle engine I pass two objects into it like this...

<B>battleEngine.startBattle (badBat, Ben);</B>

however my method that starts the battle stats like this...

<B>static void startBattle(Bat badBat, Player Ben)</B>

I can only accept a Bat object into it so if I wanted to fight a troll by using

<B>battleEngine.startBattle (Troll, Ben);</B>

if wouldnt work because the engine would be expecting a bat.. how do I go arround making it accept any enemy object... and using that as the person I am fighitng???
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you should do is create a super class or a class that all your fighters extend. Then, accept that super class as the method argument. Example...









Something like that anyway. Should get you going.
 
Julian Kennedy
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, you need to define an Enemy class or interface and have Bat and Troll either extend it or implement it. A further design consideration might be whether Bat and Troll should actually be separate classes at all. Do they have any different attributes or methods (or method implementations) or is it just the values of the attributes that differ? On the other hand you might want to consider having a FlyingEnemy class that extends the generic Enemy class and then have Bat extend FlyingEnemy for example.

Does that give you some ideas?

Jules
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this is a good candidate for the Games Forum.
 
Nick George
Ranch Hand
Posts: 815
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a note... this forum uses UBB code,

use array brackets, [], not angle brackets to embolden things.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!