Followers 0

# Am I Over Thinking This ?

## 14 posts in this topic

I have been working on a parent class that will handle every interactive item that will be generated on the map, however I think I may be "over thinking" this a bit too much - or maybe I am not abstracting it enough.

This class will handle trees, rocks, plants, and mining nodes - what do you think ?


public abstract class InteractiveObject {
static String defaul1 = "Error";
static String defaul2 = "E";
static int defaul3 = -1;

String name;
String type;
String inspect;
String skill;
String tool_required;
int tool_quality;
int tool_damage;
int skill_level;
int health;
int regen;
int experance;
int rarity; // Chance to spawn on map ( x in 10000 )
String[] state = new String[2];
//LootNode loot;

public InteractiveObject(){
name = defaul1;
type = defaul1;
inspect = defaul1;
skill = defaul1;
tool_required = defaul1;
tool_quality = defaul3;
tool_damage = defaul3;
skill_level = defaul3;
health = defaul3;
regen = defaul3;
experance = defaul3;
rarity = defaul3;
state[0] = defaul2;
state[1] = defaul2;
//loot = new LootNode(defaul1);
}

public String getName(){return name;}
public String getType(){return type;}
public String getInspect(){return inspect;}
public String getSkill(){return skill;}
public int getSkillLevel(){return skill_level;}
public int getHealth(){return health;}
public int getRegenerationRate(){return regen;}
public int getExperance(){return experance;}
public int getRarity(){return rarity;}
public String[] getStates(){return state;}

}


1

##### Share on other sites

1. people other than the coders can change the data.

2. no re-compile required when you change the data.

the slick way to do it is to alt-tab out of the game, edit the data file, then use a menu pick in the game to re-load the data file without quitting the game. or better yet, build the data  file editor into the game itself - but this might be overkill, depending on the game and the complexity of the data.  constant values for object type definitions like you're dealing with can easily be handled with a simple text file.  for something more complex like a heightmap, an internal or external editor would probably be called for.

as for the "all-in-one"  objecttype struct, i often debate this issue myself when starting a new title.  all in one is appealing in its perceived simplicity, but can be inefficient in terms of memory usage, cache friendliness, etc. due to unused variables.

some unused variables are ok. but its usually better to divvy things up into groups with similar sets of variables.

composition and components can reduce / eliminate unused variables, by giving you multiple simple struct types to work with.

1

##### Share on other sites

and definitely use #defined constants or enums instead of strings where possible. much faster. note that enums may have some type checking overhead that #defined constants don't have.

0

##### Share on other sites

Your class will end up being much bigger than that. The class would end up being a  World Class in that case.

You have the world, and then you have things in the world. Those things can be sectioned off into different classes. You have the class of Humans and the class of Fish, and the class of trees. Each class is, in its own respect, is very detailed. You have so many different kinds of trees, with various unique properties.

Now, you have one class handling rocks and trees and plants and... get the point?

If you break down your classes and use inheritance for certain things, then it will make adding to the class easier in the long run. Also, your classes would be more re-usable for future things.

Perhaps you want trees in your next game, but not rocks?

Edited by Tutorial Doctor
0

##### Share on other sites

Your class will end up being much bigger than that. The class would end up being a  World Class in that case.

You have the world, and then you have things in the world. Those things can be sectioned off into different classes. You have the class of Humans and the class of Fish, and the class of trees. Each class is, in its own respect, is very detailed. You have so many different kinds of trees, with various unique properties.

I don't really enjoy extreme programming, but it has one principle I stick to: "You aren't gonna need it." http://en.wikipedia.org/wiki/You_aren't_gonna_need_it

Basically, don't add features for the future. Add features and refactor for the present. This rock/tree thing is a great example. If I made a game, at the beginning, there's probably not really any difference between a rock and a tree. They're both just parts of the scenery - two immobile objects with different 3D representations but the same code. So why should I make a Rock class and a Tree class right at the beginning? Maybe I'll be able to mine rocks and chop down trees, but that could also just start out as different values in a couple of variables - which tool type works, what material comes out, etc. - exactly like the OP describes. We could argue about data types and minor details but the general idea is there. Why make two classes? It doesn't gain me anything for the present.

If it gets to the point where there are differences between rocks and trees, they can be refactored into two separate classes. There's not much point in doing it earlier.

Perhaps you want trees in your next game, but not rocks?

Maybe I want traffic cones and mailboxes in my next game, and the generic InteractiveObject would work for those just fine by itself.

0

##### Share on other sites

They're both just parts of the scenery - two immobile objects with different 3D representations but the same code. So why should I make a Rock class and a Tree class right at the beginning?

Good point, if that is the case, certainly they can go to one class. But then why are mining nodes apart of that same class? In the class you see all sorts of properties and stuff. If rocks and trees are not using any of those properties, then perhaps they should be separated out.

There would be one class for "Scenery Objects" and another for objects that can be interacted with. If they can be interacted with in the same manner (as in something like minecraft) then again, they could be in the same class. And I guess the mining node would fit if it is interacting with the rocks and trees. I guess it depends on the game.

Edited by Tutorial Doctor
0

##### Share on other sites

I don't really enjoy extreme programming, but it has one principle I stick to: "You aren't gonna need it." http://en.wikipedia.org/wiki/You_aren't_gonna_need_it

I've fixed the link for you:

Not quite...

The apostrophe breaks the link, even when using the forum's Link button. Using an alternative link works:

Otherwise, typing it in manually you can make it work, though:

[ url = http//etc ] Clicky[ / url]

Clicky

0

##### Share on other sites

Hmmm, odd.  It was working before I clicked post.

0

## Create an account

Register a new account