Fixed some memory leaks, and took the address-related properties out of Player.
5 // Created by Jens Alfke on 7/3/08.
6 // Copyright 2008 Jens Alfke. All rights reserved.
14 @implementation Player
17 - (id) initWithGame: (Game*)game
27 - (id) initWithName: (NSString*)name
37 - (id) initWithCoder: (NSCoder*)decoder
41 _game = [decoder decodeObjectForKey: @"game"];
42 _name = [[decoder decodeObjectForKey: @"name"] copy];
43 _local= [decoder decodeBoolForKey: @"local"];
44 _extraValues = [[decoder decodeObjectForKey: @"extraValues"] mutableCopy];
49 - (void) encodeWithCoder: (NSCoder*)coder
51 [coder encodeObject: _game forKey: @"game"];
52 [coder encodeObject: _name forKey: @"name"];
53 [coder encodeBool: _local forKey: @"local"];
54 [coder encodeObject: _extraValues forKey: @"extraValues"];
60 [_extraValues release];
65 - (id)valueForUndefinedKey:(NSString *)key
67 return [_extraValues objectForKey: key];
70 - (void)setValue:(id)value forUndefinedKey:(NSString *)key
73 _extraValues = [[NSMutableDictionary alloc] init];
75 [_extraValues setObject: value forKey: key];
77 [_extraValues removeObjectForKey: key];
81 @synthesize game=_game, name=_name, local=_local;
83 - (BOOL) isCurrent {return self == _game.currentPlayer;}
84 - (BOOL) isFriendly {return self == _game.currentPlayer;} // could be overridden for games with partners
85 - (BOOL) isUnfriendly {return ! self.friendly;}
87 + (NSArray*) keyPathsForValuesAffectingCurrent {return [NSArray arrayWithObject: @"game.currentPlayer"];}
92 return [_game.players indexOfObjectIdenticalTo: self];
95 - (Player*) nextPlayer
97 return [_game.players objectAtIndex: (self.index+1) % _game.players.count];
100 - (Player*) previousPlayer
102 return [_game.players objectAtIndex: (self.index-1) % _game.players.count];
107 return [_game iconForPlayer: self.index];
110 - (NSString*) description
112 return [NSString stringWithFormat: @"%@[%@]", self.class,self.name];