here is my code
#import "GameWorld.h"
@implementation GameWorld
+(id)sharedInstance
{
static GameWorld *theInstance = nil;
if (!theInstance) {
theInstance = [[[self class] alloc] init];
}
return theInstance;
}
-(id)init
{
connections = [[NSMutableDictionary alloc] initWithCapacity:10];
Room *livingroom, *hallway1, *kitchen, *mbedroom, *bedroom2, *bedroom3, *frontdoor, *hallway2, *bathroom, *stairs, *outside;
self = [super init];
if (self) {
// Create the rooms
outside = [[Room alloc] initWithDescription:@"outside of the house"];
livingroom = [[Room alloc] initWithDescription:@"the livingroom"];
kitchen = [[Room alloc] initWithDescription:@"in the kitchen"];
mbedroom = [[Room alloc] initWithDescription:@"in the master bedroom"];
bedroom2 = [[Room alloc] initWithDescription:@"in the second bedroom"];
bedroom3 = [[Room alloc] initWithDescription:@"in the third bedroom"];
hallway1 = [[Room alloc] initWithDescription:@"in the downstairs hallway"];
hallway2 = [[Room alloc] initWithDescription:@"in the upstairs hallway"];
frontdoor = [[Room alloc] initWithDescription:@"door to get outside"];
bathroom = [[Room alloc] initWithDescription:@"in the bathroom"];
stairs = [[Room alloc] initWithDescription:@"in the stairway"];
outside.image = @"outside.jpg";
livingroom.image = @"livingroom.jpg";
kitchen.image = @"kitchen.jpg";
frontdoor.image = @"frontdoor.jpeg";
mbedroom.image = @"mbedroom.jpg";
bedroom2.image = @"bedroom2.jpg";
bedroom3.image = @"bedroom3.jpg";
hallway1.image = @"hallway1.jpg";
hallway2.image = @"hallway2.jpg";
bathroom.image = @"bathroom.jpg";
stairs.image = @"stairs.jpg";
//Add items to the outside room
[outside dropItem:[[[Item alloc] initWithName:@"Trees"] autorelease]];
[outside dropItem:[[[Item alloc] initWithName:@"Bicycle"] autorelease]];
[mbedroom dropItem:[[[Item alloc] initWithName:@"TV"] autorelease]];
[mbedroom dropItem:[[[Item alloc] initWithName:@"shirts"] autorelease]];
[bedroom2 dropItem:[[[Item alloc] initWithName:@"Bed"] autorelease]];
[bedroom2 dropItem:[[[Item alloc] initWithName:@"Mirror"] autorelease]];
[bathroom dropItem:[[[Item alloc] initWithName:@"bathtub"]autorelease]];
[hallway1 dropItem:[[[Item alloc] initWithName:@"Picture"] autorelease]];
[bedroom3 dropItem:[[[Item alloc] initWithName:@"trunk"] autorelease]];
[hallway2 dropItem:[[[Item alloc] initWithName:@"Picture"] autorelease]];
[bedroom3 dropItem:[[[Item alloc] initWithName:@"Dresser"] autorelease]];
[kitchen dropItem:[[[Item alloc] initWithName:@"Fridge"]autorelease]];
[livingroom dropItem:[[[Item alloc] initWithName:@"Chair"]autorelease]];
[livingroom dropItem:[[[Item alloc] initWithName:@"TV"]autorelease]];
[mbedroom pickupItem:@"Mirror"];
// extra room to connect later
//Room *room1 = [[Room alloc] initWithDescription:@"in the laundry room"];
//Room *room2 = kitchen;
//Room *trigger = hallway1;
//NSString *exit1 = @"south";
//NSString *exit2 = @"north";
//NSArray *tempArray = [NSArray arrayWithObjects: room1, room2, exit1, exit2, nil];
//[connections setObject:tempArray forKey:trigger];
// another extra room to connect later
Room *room1 = kitchen;
Room *room2 = hallway1;
Room *room3 = mbedroom;
Room *room4 = bedroom2;
Room *room5 = livingroom;
NSArray *myArray = [NSArray arrayWithObjects:room1, room2, room3,room4, room5, nil];
//[connections setObject:tempArray forKey:trigger];
//add observer to NSNotificationCenter
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(makeConnection:) name:@"playerDidEnterRoom" object:nil];
// Initialize room exits
[outside setExit:@"east" :frontdoor];
[frontdoor setExit:@"east" :livingroom];
[frontdoor setExit:@"west" :outside];
[livingroom setExit:@"west" :frontdoor];
[livingroom setExit:@"north" :hallway1];
[livingroom setExit:@"east" :kitchen];
[kitchen setExit:@"west" :livingroom];
[hallway1 setExit:@"north" :mbedroom];
[hallway1 setExit:@"east" :stairs];
[hallway1 setExit:@"south" :livingroom];
[mbedroom setExit:@"south" :hallway1];
[stairs setExit:@"up" :hallway2];
[stairs setExit:@"down" :hallway1];
[hallway2 setExit:@"north" :bedroom2];
[hallway2 setExit:@"east" :bathroom];
[hallway2 setExit:@"south" :bedroom3];
[hallway2 setExit:@"west" :stairs];
[bedroom2 setExit:@"south" :hallway2];
[bathroom setExit:@"west" :myArray];
[bedroom3 setExit:@"north" :hallway2];
[hallway1 release];
[kitchen release];
[mbedroom release];
[bedroom2 release];
[bedroom3 release];
[frontdoor release];
[hallway2 release];
[bathroom release];
[stairs release];
// Stores the entrance room
entrance = livingroom;
}
return self;
}
-(Room *)getEntrance
{
return entrance;
}
-(void)makeConnection:(NSNotification *)notification
{
Player *thePlayer = [notification object];
NSArray *action = [connections objectForKey:[thePlayer currentRoom]];
if (action) {
NSLog(@"\nI got action!\n");
[[action objectAtIndex:0] setExit:[action objectAtIndex:3] :[action objectAtIndex:1]];
[[action objectAtIndex:1] setExit:[action objectAtIndex:2] :[action objectAtIndex:0]];
[connections removeObjectForKey:[thePlayer currentRoom]];
if ([connections count] == 0) {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
//[connectingRoom setExit:@"south" :extraRoom];
//[extraRoom setExit:@"north" :connectingRoom];
//[[NSNotificationCenter defaultCenter] removeObserver:self];
}
}
-(void)dealloc
{
[entrance release];
[connections release];
[super dealloc];
}
@end

New Topic/Question
Reply



MultiQuote


|