140 |
/** |
/** |
141 |
* Change the player's ship. |
* Change the player's ship. |
142 |
* The ship must exist. |
* The ship must exist. |
143 |
* Post an notification named "updatePlayer" containing the current object. |
* Post an notification named "updatePlayer" containing the current game and |
144 |
|
* the current object. |
145 |
*/ |
*/ |
146 |
-(void) setShip: (HgShip *)ship |
-(void) setShip: (HgShip *)ship |
147 |
{ |
{ |
149 |
|
|
150 |
ASSIGN(_ship, ship); |
ASSIGN(_ship, ship); |
151 |
|
|
152 |
[[NSNotificationCenter defaultCenter] |
[[NSNotificationCenter defaultCenter] postNotificationName: @"updatePlayer" |
153 |
postNotificationName:@"updatePlayer" object:self]; |
object: _game |
154 |
|
userInfo: [NSDictionary dictionaryWithObject: self |
155 |
|
forKey: @"HgPlayer"]]; |
156 |
} |
} |
157 |
|
|
158 |
/** |
/** |
159 |
* Change the player's team. |
* Change the player's team. |
160 |
* The team must exist. |
* The team must exist. |
161 |
* Post an notification named "updatePlayer" containing the current object. |
* Post an notification named "updatePlayer" containing the current game and |
162 |
|
* the current object. |
163 |
*/ |
*/ |
164 |
-(void) setTeam: (HgTeam *)team |
-(void) setTeam: (HgTeam *)team |
165 |
{ |
{ |
167 |
|
|
168 |
ASSIGN(_team, team); |
ASSIGN(_team, team); |
169 |
|
|
170 |
[[NSNotificationCenter defaultCenter] |
[[NSNotificationCenter defaultCenter] postNotificationName: @"updatePlayer" |
171 |
postNotificationName:@"updatePlayer" object:self]; |
object: _game |
172 |
|
userInfo: [NSDictionary dictionaryWithObject: self |
173 |
|
forKey: @"HgPlayer"]]; |
174 |
} |
} |
175 |
|
|
176 |
/** |
/** |
177 |
* Add any point to the player's score. |
* Add any point to the player's score. |
178 |
* Post an notification named "updatePlayer" containing the current object. |
* Post an notification named "updatePlayer" containing the current game and |
179 |
|
* the current object. |
180 |
*/ |
*/ |
181 |
-(void) addPoint: (int)point |
-(void) addPoint: (int)point |
182 |
{ |
{ |
183 |
_score += point; |
_score += point; |
184 |
|
|
185 |
[[NSNotificationCenter defaultCenter] |
[[NSNotificationCenter defaultCenter] postNotificationName: @"updatePlayer" |
186 |
postNotificationName:@"updatePlayer" object:self]; |
object: _game |
187 |
|
userInfo: [NSDictionary dictionaryWithObject: self |
188 |
|
forKey: @"HgPlayer"]]; |
189 |
} |
} |
190 |
|
|
191 |
/** |
/** |
203 |
@implementation HgPlayer (NSCoding) |
@implementation HgPlayer (NSCoding) |
204 |
|
|
205 |
/** |
/** |
206 |
* NSCoding method |
* NSCoding method to encode and decode objects |
|
* to encode and decode objects |
|
207 |
*/ |
*/ |
208 |
- (void)encodeWithCoder: (NSCoder *)encoder |
- (void)encodeWithCoder: (NSCoder *)encoder |
209 |
{ |
{ |
220 |
[decoder decodeValueOfObjCType: "I" at: &_identifier]; |
[decoder decodeValueOfObjCType: "I" at: &_identifier]; |
221 |
NSNumber *numIdent = [NSNumber numberWithInt: _identifier]; |
NSNumber *numIdent = [NSNumber numberWithInt: _identifier]; |
222 |
|
|
223 |
HgPlayer *playerObject = [[_game players] objectForKey: numIdent]; |
HgGame *currentGame = [HgGame currentGame]; |
224 |
|
HgPlayer *playerObject = [[currentGame players] objectForKey: numIdent]; |
225 |
|
|
226 |
if (playerObject != nil) |
if (playerObject != nil) |
227 |
{ |
{ |
228 |
DESTROY(self); |
DESTROY(self); |