Results 1 to 3 of 3
- 10-29-2010, 09:06 PM #1
How can I implement an ArrayList in an enum?
I'm making a game, and I'm trying to create a way for the character to move from room to room. My room objects are enums, and I want them to hold an ArrayList of Door objects (since there may be a different number of doors in each room), and let the player activate() the door which will transport them to the room object specified by the door.
Heres some of my code:
I have no idea how to define each rooms exits and then add the doors to its specific ArrayList so that it can be constructed.Java Code:public enum Room { /* * Defines all rooms in the game */ TestRoom1("Test Room", Engine.printFileText("text_files/test_room_description.txt"), 101), TestRoom2("Test Hall", Engine.printFileText("text_files/test_hall_description.txt"), 100); public int ID; public String name; public String description; ArrayList<Door> exits; Room(String _name, String _description, int _ID) { exits = new ArrayList<Door>(); ID = _ID; name = _name; description = _description; } // Rest of class ommited
Thanks!
- 10-29-2010, 10:53 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Why enums? What design you want to accomplish with this?
Here is some example just to give you idea in which direction you could go:
Object-Oriented Software Development Using Java | Source Code
hope that can help, but that is just beginning !
-
I don't think that Room should be an enum but rather a class; it just seems to me that Room is not an inert constant but rather a entity that may change, may be subclassed, and may need to have multiple instances. Room properties may be best coded as enums (may), but to not Room itself. That's just my view, and others might see it differently.
Similar Threads
-
Setting values from One Enum type to another enum type.
By reach2sudhakar in forum New To JavaReplies: 3Last Post: 09-23-2010, 06:02 PM -
Java Project Trouble: Searching one ArrayList with another ArrayList
By BC2210 in forum New To JavaReplies: 2Last Post: 04-21-2008, 11:43 AM -
Enum example
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:34 PM -
How to use enum
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:34 PM -
Enum?
By vgbhagavan in forum Advanced JavaReplies: 0Last Post: 06-14-2007, 02:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks