#import "PlayerViewController.h"
@implementation PlayerViewController
@synthesize description;
@synthesize commands;
@synthesize subjects;
@synthesize availableCommands;
@synthesize player;
@synthesize currentCommand;
#pragma mark TableView Delegate Methods
-(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
return indexPath;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == commands) {
NSString *commandName = [availableCommands keyForRow:[indexPath row]];
self.currentCommand = [availableCommands objectForKey:commandName];
if ([[currentCommand name] isEqualToString:@"Go"]) {
[subjects setDataSource:[[player currentRoom] exits]];
}
if ([[currentCommand name] isEqualToString:@"Look"]) {
composite = [[CompositeContainer alloc] init];
[composite addContainer:[[player currentRoom] exits]];
[composite addContainer:[[player currentRoom] items]];
[subjects setDataSource:composite];
}
if ([[currentCommand name] isEqualToString:@"Back"]) {
[subjects setDataSource:[[player currentRoom] back]];
}
if ([[currentCommand name] isEqualToString:@"Quit"]) {
[subjects setDataSource:[[player getEntrance] exits]];
}
if ([[currentCommand name] isEqualToString:@"Pickup"]) {
[subjects setDataSource:[[player currentRoom] items]];
}
if ([[currentCommand name] isEqualToString:@"Drop"]) {
[subjects setDataSource:[[player currentRoom] items]];
}
[subjects reloadData];
}
if (tableView == subjects) {
NSString *exit = [[[player currentRoom] exits] keyForRow: [indexPath row]];
[currentCommand setSecondWord:exit];
[currentCommand execute:player];
[description setText:[[self.player currentRoom] description]];
[subjects setDataSource:nil];
[subjects reloadData];
}
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#import "Player.h"
@implementation Player
@synthesize currentRoom;
-(id)init
{
[self initWithRoom:[[NSNull alloc] init]];
return self;
}
-(id)initWithRoom:(Room *)start
{
[super init];
self.currentRoom = start;
return self;
}
-(void)walk:(NSString *)exit
{
self.currentRoom = [currentRoom getExit:exit];
}
-(void)back:(NSString *)back
{
self.currentRoom = [currentRoom getExit:exit - 1];
}

New Topic/Question
Reply



MultiQuote



|