Java enum pairs / "subenum" or what exactly?

Posted by vemalsar on Game Development See other posts from Game Development or by vemalsar
Published on 2011-02-10T11:35:02Z Indexed on 2011/02/10 15:33 UTC
Read the original article Hit count: 258

Filed under:
|

I have an RPG-style Item class and I stored the type of the item in enum (itemType.sword). I want to store subtype too (itemSubtype.long), but I want to express the relation between two data type (sword can be long, short etc. but shield can't be long or short, only round, tower etc). I know this is wrong source code but similar what I want:

enum type
{
    sword;
}

//not valid code!
enum swordSubtype extends type.sword
{
    short,
    long
}

Question: How can I define this connection between two data type (or more exactly: two value of the data types), what is the most simple and standard way?

  1. Array-like data with all valid (itemType,itemSubtype) enum pairs or (itemType,itemSubtype[]) so more subtype for one type, it would be the best. OK but how can I construct this simplest way?

  2. Special enum with "subenum" set or second level enum or anything else if it does exists

  3. 2 dimensional "canBePairs" array, itemType and itemSubtype dimensions with all type and subtype and boolean elements, "true" means itemType (first dimension) and itemSubtype (second dimension) are okay, "false" means not okay

  4. Other better idea

Thank you very much!

© Game Development or respective owner

Related posts about java

Related posts about rpg