This may be a duplicate question as I don\'t know to phrase the search query. I\'m creating a Zork-like text based game in Java where the character moves to different rooms whic
You could implement this using an array:
class Room {
private Room[] exits = new Room[4];
}
In this example, exits[0]
could contain a reference to the room to the north, exits[1]
the room to the east, and so on. If an element contains null
then that might represent no exit in that direction.
Note that you can create nonlinear data structures using this method, such as A -> B -> C -> A.