Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

More about StackableBoard

  Asked By: Zobah    Date: Feb 26    Category: Java    Views: 428
  

I was thinking about this today and I wanted to have a class heirarchy
like this.

Object
-Impassable
--Rock
--Tree
-Passable
--Player
--NPC
---Human
---Creature
----etc.

I could do that all with extending, I know. But then each of these
Objects I would have to have a variable to tell if it's Passable or
not. Is there a way I can tell if an object extends Passable or
Impassable somewhere down the chain? I think that would be the best
and most efficient way of doing it.

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Iris Sanders     Answered On: Feb 26

Make the concept of passability a boolean variable.
Those that are inpassable have it set to false, those
that are passable have it set to true.

Alternatively, you can make 2 empty interfaces for
Passable and Impassable. There is a way to determine
if an object  implements these, i believe it is in the
Class class.

 
Answer #2    Answered By: Olga Allen     Answered On: Feb 26

Subclasses inherit all public data. so as long as there is a variable  in the
super class  u shud be able to access it from child class. I would declare a
variable 'boolean passable = TRUE' in the parent class and
make it final.

 
Answer #3    Answered By: Botan Suzuki     Answered On: Feb 26

I can see a couple ways to do what you're trying. One way is to make
a base abstract class  for everything. Maybe call it GameObject.
GameObject would have a member variable  such as isPassable.

Another way is to make two interfaces: Passable and Impassable. If
an object  is Passable, it implements the Passable interface. You
could just check if it's passable by doing something like:

if (myObject instanceof Passable) ...

I would personally stick with the first method because the second
method allows you to have an object that's both passable and
impassable and the two interfaces would be blank. Try to think of
the things that each object in your game would need, regardless of
whether it's passable or not, and store that stuff in GameObject.

 
Didn't find what you were looking for? Find more on More about StackableBoard Or get search suggestion and latest updates.

Related Topics:



Tagged:  

 
 
 

Related Post