Object List (help please)
Hey, I was wondering how I could add objects to an array list as they are created. I have a class that consists of a method that creates "Room" objects and as each one is created I need to add it to an array list:
publicstaticvoid createRooms()
{
Room
a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,
a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,
a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,
a4,b4,c4,d4,e4,f4,g4,h4,i4,j4,
a5,b5,c5,d5,e5,f5,g5,h5,i5,j5,
a6,b6,c6,d6,e6,f6,g6,h6,i6,j6,
a7,b7,c7,d7,e7,f7,g7,h7,i7,j7;
a1=new Room("a1");
a2=new Room("a2");
a3=new Room("a3");
a4=new Room("a4");
a5=new Room("a5");
a6=new Room("a6");
a7=new Room("a7");
b1=new Room("b1");
b2=new Room("b2");
b3=new Room("b3");
//etc.....
//and the room class:
publicclass Room
{
private String description;
private HashMap<String, Room> exits;
publicstatic Room currentRoom;
public ArrayList roomList =new ArrayList();
public Random numGEN =new Random();
public Room(String description)
{
this.description = description;
exits =new HashMap<String, Room>();
roomList.add(this);
}
What I need is for each room object's name to be added into the array list as a room object, so, roomList(0) = a1, roomList(1) = a2, etc...
Thanks

