this is what i have
[outside dropItem:[[[Item alloc] initWithName:@"Bicycle"] autorelease]]; [outside pickupItem:<#(NSString *)theItem#>];
i just would like some help with this.
Posted 25 July 2011 - 08:11 PM
[outside dropItem:[[[Item alloc] initWithName:@"Bicycle"] autorelease]]; [outside pickupItem:<#(NSString *)theItem#>];
Posted 25 July 2011 - 10:38 PM
Posted 25 July 2011 - 10:52 PM
-(id)init
{
return [self initWithDescription:@"No Description"];
}
-(id)initWithDescription:(NSString *)aDescription
{
self = [super init];
self.description = aDescription;
exits = [[NamedObjectContainer alloc] initWithCapacity:10];
exits.name = @"Exits";
items = [[NamedObjectContainer alloc] initWithCapacity:10];
items.name = @"Items";
image = @"room.jpg";
return self;
}
-(id)copyWithZone: (NSZone *) zone
{
Room *newRoom = [[Room allocWithZone:zone] initWithDescription:self.description];
newRoom.exits = exits;
return newRoom;
}
-(void)setExit:(NSString *)exit:(Room *)theRoom
{
[exits setObject:theRoom forKey:exit];
}
-(Room *)getExit:(NSString *)exit
{
return [exits objectForKey:exit];
}
-(NSUInteger)hash
{
return [description hash];
}
-(BOOL)isEqual:(id)object
{
return [description isEqual:[object description]];
}
-(NSString *)name
{
return description;
}
-(void)dropItem:(Item *)anItem
{
[items setObject:anItem forKey:[anItem name]];
}
-(Item *)pickupItem:(NSString *)theItem
{
return [[[Item alloc] init] autorelease];
}
-(void)dealloc
{
[description release];
[exits release];
[items release];
[image release];
[super dealloc];
}
@end
Posted 26 July 2011 - 11:41 AM
Posted 26 July 2011 - 07:12 PM
#import "NamedObjectContainer.h"
@implementation NamedObjectContainer
@synthesize name;
-(id)initWithCapacity:(NSUInteger)numItems
{
theContainer = [[NSMutableDictionary alloc] initWithCapacity:numItems];
sortedKeys = [[NSMutableArray alloc] initWithCapacity:numItems];
return self;
}
-(void)setObject:(id)anObject forKey:(id)aKey
{
[sortedKeys addObject:aKey];
[theContainer setObject:anObject forKey:aKey];
}
-(id)objectForKey:(id)aKey
{
return [theContainer objectForKey:aKey];
}
-(NSUInteger)count
{
return [theContainer count];
}
-(NSArray *)allKeys
{
return sortedKeys;
}
-(NSString *)keyForRow:(NSInteger)row
{
return [sortedKeys objectAtIndex:row];
}
#pragma mark -
#pragma mark Table View Data Source Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *GameTableIdentifier = @"GameTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:GameTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:GameTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
NSArray *theKeys = [self allKeys];
[[cell textLabel] setText:[theKeys objectAtIndex:row]];
id<NamedObjectProtocol> tempObject = [theContainer objectForKey:[theKeys objectAtIndex:row]];
[[cell imageView] setImage:[UIImage imageNamed:[tempObject image]]];
return cell;
}
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return name;
}
@end
Posted 26 July 2011 - 08:38 PM
Posted 26 July 2011 - 09:14 PM
GWatt, on 26 July 2011 - 09:38 PM, said:
Posted 27 July 2011 - 07:22 AM
-(void) removeObjectForKey:(id)aKey; -(void) removeObjectsForKeys:(NSArray *)keyArray;
-(void) removeObject:(id)anObject;
-(Item *) pickupItem:(NSString *) theItem {
return [items removeItemByName: theItem];
}
-(Item *) removeItemByName:(NSString *) name {
Item *item = [theContainer objectForKey: name];
[theContainer removeObjectforKey: name];
[sortkeys removeObject: name];
return item;
}
This post has been edited by GWatt: 27 July 2011 - 07:22 AM
Posted 27 July 2011 - 09:59 AM
//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:@"shirts"];
|
|
Query failed: connection to localhost:3312 failed (errno=111, msg=Connection refused).
|
