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 _uuid = [[decoder decodeObjectForKey: @"UUID"] copy];
44 _address = [[decoder decodeObjectForKey: @"address"] copy];
45 _addressType = [[decoder decodeObjectForKey: @"addressType"] copy];
46 _local= [decoder decodeBoolForKey: @"local"];
51 - (void) encodeWithCoder: (NSCoder*)coder
53 [coder encodeObject: _game forKey: @"game"];
54 [coder encodeObject: _name forKey: @"name"];
55 [coder encodeObject: _uuid forKey: @"UUID"];
56 [coder encodeObject: _address forKey: @"address"];
57 [coder encodeObject: _addressType forKey: @"addressType"];
58 [coder encodeBool: _local forKey: @"local"];
66 [_addressType release];
71 @synthesize game=_game, name=_name, UUID=_uuid, address=_address, addressType=_addressType, local=_local;
73 - (BOOL) isCurrent {return self == _game.currentPlayer;}
74 - (BOOL) isFriendly {return self == _game.currentPlayer;} // could be overridden for games with partners
75 - (BOOL) isUnfriendly {return ! self.friendly;}
77 + (NSArray*) keyPathsForValuesAffectingCurrent {return [NSArray arrayWithObject: @"game.currentPlayer"];}
82 return [_game.players indexOfObjectIdenticalTo: self];
85 - (Player*) nextPlayer
87 return [_game.players objectAtIndex: (self.index+1) % _game.players.count];
90 - (Player*) previousPlayer
92 return [_game.players objectAtIndex: (self.index-1) % _game.players.count];
97 return [_game iconForPlayer: self.index];
100 - (NSString*) description
102 return [NSString stringWithFormat: @"%@[%@]", self.class,self.name];