Of course. My understanding is that the getStrength method should be in the super class, and only the race-specific stat tweaks in the sub classes.
Thanks for confirming all of this; I really appreciate it.
Of course. My understanding is that the getStrength method should be in the super class, and only the race-specific stat tweaks in the sub classes.
Thanks for confirming all of this; I really appreciate it.
No problem, just as tip, the appreciate button gives the use medals, which is a very nice reward No pressure, but if anyone helps you, and you feel grateful, just hit that button!
And yeah, I was just trying to show you about sub classes and inheritance. That was kind of a poor example on my part, but I think you know what I was trying to say!
Hey, I’m all for giving props where they’re due, but I’m not seeing an appreciate button anywhere. Is that something I need to have a minimum post count/age to be able to do or am I just overlooking it?
try far right-top on a post
Yeah I only have the option to Reply or Quote on others’ posts. I’ll revisit this question later and give credit where it’s due.
Thanks again all.
Ah, yes you need to post more on the forums before you can appreciate anything!
Looks like the option just popped up. I guess the magic number was 5 posts. I gave each of you a karma and it’s not letting me do it any more for an hour, so there you have it
Here, have your first medal, courtesy of me!
Enums anyone?
In addition to what the other said (which were all great)
Also depending on how might flexibility you might want.
You might consider having some rand.nextInt(40)+80; for health or something, to give some ‘variety’ to your particular Orc.
you can also, depending if you have their name anywhere, you can have a prefix list like
String prefix[] = {“Mighty”, “Strong”, “Evil”, “Dastardly”, “Weak”};
name = prefix[rand.nextInt(5)] + " Orc";
So you have different Mighty Orcs! Or other variations
If your game is visual, you can add a very simple filter/shade to your texture to give it a slight color hue/tint(many libraries have a way of handling this quite easily) or scaleXY to make them slightly different in size. Depending upon your game.
This may be a bit advanced or a jump to get into, but a component-system based approach is quite efficient, from my own experience. Essentially, each entity is simply an ID that’s assigned predefined component classes - like health, or damage, or movement - that another class, a system or handler, takes into account to make the entity do what you want it to.
The one I like currently is the Artemis Entity System. http://gamadu.com/artemis/
composition over inheritance.
For this type of game, yeah, but let’s not try to confuse him too much ;D
What’s confusion about using data rather than hardcoding? It’s easier to write, maintain and understand. There’s not much need even for composition…just be data driven.
Well I think one should learn the basic OOP Pattern before going on to others.
OO isn’t a pattern. Data-driven and design by composition is pretty much the whole point.
Yeah. I love enums, but sometimes, I feel like it isn’t enough. You can do enums, or you can make a static class like minecraft does for blocks. Like, every block extends Block, and all blocks are predefined objects in it, like this:
class Block {
public static Block grass = ((Block) new Grass());
public static Block dirt = ((Block) new Dirt());
public Block(float hardness, int id) {
...
}
public abstract void render(Graphics g, float x, float y);
...
}
It seems to give more options than enums… Instead of just defining constructors, you can define methods as well!
But enums can have functions?
It really depends on what you want out of your program. Both are viable solutions, they both get the job done in different ways. However, you’ll need an actual class to host the enum, so depending on how you want your project to be set up, you’ll probably just need to go with static functions rather than an enum. If that makes sense! Typing on a phone is rather bad for going back over your post
The OP says he only needs to override data, so enums are the easiest way of doing things for this situation.
No need to worry about functions.
Using enums, anonymous inner classes, etc all require learning new language feature(s) AND they don’t scale very well and are pretty much only a minor step up from hardcoding (creating a sub-class for each monster). They can all be reasonable choices if the number of monsters is small, but why not do it one of the reasonable ways from the start?
Maybe I’m crazy but even for a beginner I’d suggest mimicking what you’d do in real life with a pencil-and-paper RPG. Let’s say you have a green-and-pink polka-dotted dragon fighting 10 rabies-infested-vorpal-furry-bunnies. You look up the “bunnies” in your Monsterz Emanuel do you expect to see:
rabies-infested-vorpal-furry-bunny
Is a vorpal-furry-bunny with “And they have rabies!” appended to the description. "+2% of inflicting “rabies” per hit appended to the attack description, etc.
Now you go lookup: vorpal-furry-bunny and they define how they are different from “furry-bunny” which is defined how it’s different from…
Nah, what you expect to see a complete description for pretty much every monster. Now when you proceed to play out he combat do you make 10 photocopies of the bunny description? Nope you jot down on a piece of paper the things that make each one unique (say its starting hit-points). You refer to the book when you need the definition and the piece of paper to track the changing information.
Monsterz Emanuel in code:
/** One instance of this class per monster defination (entry in Emanuel)*/
public class MonsterDesc
{
int maxHP;
int ar;
int dr;
int exp;
String desc;
}
An entry on the piece of paper in code:
public class Monster
{
MonsterDesc desc; // what kind of monster am I?
int hp;
}