I working on a text-based adventure game in objective-c and I’ve got a lot of the parts completed including the input/output system, and command parser. The only thing I can’t figure out is the best way to create the “rooms”.
At first I tried using XML to store them and then using NSXMLParser to read them but that didn’t allow for enough complexity.
So now I’ve decided to create a class “AbstractLocation” and create a subclass for each room.
But, I’m having trouble connecting everything. These are my classes:
Controller
Controls the input/output and core parts of the game
AbstractLocation
A generic room for the game that can be subclassed to create each specific room
CreateMap
Creates each specific room from the AbstractLocation class
Location_room1
Location_room2
ect…
I’m wondering how to access the instance of Controller class that was created in Interface Builder from each Location_roomx, because each room is created programmatically in the CreateMap class so I can’t use an IBOutlet.
If am also open to suggestions for a better way to create the rooms system for the game.
You don’t need IBOutlet.
Just define a property on AbstractLocation, and in the code that creates the rooms, assign a pointer to the Controller to it.
The point of IBOutlet is to let Interface Builder do the same kind of thing, but without code. When you are writing the code, you don’t need IBOutlet, you just need a property, and code to assign a value to it.