Good evening.
I hope this is the right section, if not, I'm really sorry.
(Sorry for my bad english too)
I really have a big problem, I've been on it for days, and I can't find a good way to solve it, so I hope someone here can help me.
I've to create a Text Adventure for an exam.
I've done most of the work, but now I'm stuck because I have to "create the world" using a file given by our teacher.
Long story short, the problem is that I don't know how to do the "Item" class.
I have to build it using this strings:
(I've translated them, so, probably, there are full of grammatical error, but the point is the syntax)
ITEMS OGG_1 Grog Old Grog OGG_2 ComputerDisk Disk of Stan's computer Talk to Elaine # This message will appear when the disk is used with the Computer. OGG_5 drawer ship desk's drawer OGG_6 desk ship's desk OGG_5 # the drawer is inside the desk OGG_8 Computer Stan's Computer OGG_9 Letter Governor's letter Don't touch my daughter! # message of the letter OGG_10 Trashcan Bar trashcan OGG_9 # the letter is inside the trashcan OGG_11 Botton Ship botton APERT_3 # the botton open the trapdoor OGG_12 Pill Life pill (TM) LOC_6 # the pill, if eaten, brings you in the governor's palace
Now, the BIG problem is that every Item must have different actions...
For example, the Letter can only be "read"
the Botton can only be "pushed"
the pill can only be "used"
So, how should i make my "Item" class?
My first idea was something like this:
... //tmp contain the String read by file. String[] tmpItem = tmp.split("\t"); if (tmpItem[1].equals("Grog")) { Grog grog = new Grog(tmpItem[0], tmpItem[1], tmpItem[2]); } else if (tmpItem[1].equals("ComputerDisk") { ComputerDisk pcDisk = new ComputerDisk(tmpItem[0], tmpItem[1], tmpItem[2], tmpItem[3]); } else if ... ... }
But this way I should make a lot of classes (One each item) who extends the Item class, overriding only the methods I need...
...but I think it's really horrible.
I know this is a big request, but I don't want the code, just an idea, because I don't really know how to move on.
I'll appreciate every tip.