Trouble grouping objects into a list
Hello, I'm working on this program for school and I'm a bit stumped. To the point:
In a class that is known as mazeLevel which basicly creates "Room" objects, which map out the game's level using a HashMap by assigning exit key values to each room. I need to make an array list of the fields (just a list of Room variables) in the mazeLevel class. I need to be able to get an array list of rooms out of any *Level class that I may put in the game there for make a method outside the mazeLevel class.
Could anyone give me some idea of how I could do this? Do you need more information?
Would this be possible to do with a for:each loop or is there some other way, thanks. :)
[715 byte] By [
sharokua] at [2007-11-27 4:30:11]

public class mazeLevel
{
public mazeLevel()
{
}
public static void 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");
.......
a1.setExit("East",b1);
a1.setExit("South",a2);
a2.setExit("North",a1);
.........
}
public class Room
{
private String description;
private HashMap<String, Room> exits;
public static Room currentRoom;
public ArrayList<Room> roomList;
public Room(String description)
{
this.description = description;
exits = new HashMap<String, Room>();
}
// What I can't figure out.....
public void storeRooms()
{
roomList = new ArrayList();
for(mazeLevel rooms : Room)
{
}
}
> ...
> Could anyone give me some idea of how I could do
> this? Do you need more information?
> Would this be possible to do with a for:each loop or
> is there some other way, thanks. :)
I'd create a 2 dimensional array to hold those Room objects:
int rows = 7, columns = 10;
Room[][] map = new Room[rows][columns];
for(int r = 0; r < rows; r++) {
for(int c = 0; c < columns; c++) {
String value = (char)(c+'a')+""+(r+1);
System.out.println("Creating: Room("+value+")");
map[r][c] = new Room(value);
}
}