26 |
#include <Foundation/NSException.h> |
#include <Foundation/NSException.h> |
27 |
#include <Foundation/NSCoder.h> |
#include <Foundation/NSCoder.h> |
28 |
#include <Foundation/NSValue.h> |
#include <Foundation/NSValue.h> |
29 |
|
#include <Foundation/NSNotification.h> |
30 |
|
|
31 |
#include "GameEngine/HgPlayer.h" |
#include "GameEngine/HgPlayer.h" |
32 |
#include "GameEngine/HgGame.h" |
#include "GameEngine/HgGame.h" |
131 |
/** |
/** |
132 |
* Change the player's ship. |
* Change the player's ship. |
133 |
* The ship must exist. |
* The ship must exist. |
134 |
|
* Post an notification named "updatePlayer" containing the current object. |
135 |
*/ |
*/ |
136 |
-(void) setShip: (HgShip *)ship |
-(void) setShip: (HgShip *)ship |
137 |
{ |
{ |
138 |
NSParameterAssert (ship); |
NSParameterAssert (ship); |
139 |
|
|
140 |
ASSIGN(_ship, ship); |
ASSIGN(_ship, ship); |
141 |
|
|
142 |
|
[[NSNotificationCenter defaultCenter] |
143 |
|
postNotificationName:@"updatePlayer" object:self]; |
144 |
} |
} |
145 |
|
|
146 |
/** |
/** |
147 |
* Change the player's team. |
* Change the player's team. |
148 |
* The team must exist. |
* The team must exist. |
149 |
|
* Post an notification named "updatePlayer" containing the current object. |
150 |
*/ |
*/ |
151 |
-(void) setTeam: (HgTeam *)team |
-(void) setTeam: (HgTeam *)team |
152 |
{ |
{ |
153 |
NSParameterAssert (team); |
NSParameterAssert (team); |
154 |
|
|
155 |
ASSIGN(_team, team); |
ASSIGN(_team, team); |
156 |
|
|
157 |
|
[[NSNotificationCenter defaultCenter] |
158 |
|
postNotificationName:@"updatePlayer" object:self]; |
159 |
} |
} |
160 |
|
|
161 |
/** |
/** |
162 |
* Add any point to the player's score. |
* Add any point to the player's score. |
163 |
|
* Post an notification named "updatePlayer" containing the current object. |
164 |
*/ |
*/ |
165 |
-(void) addPoint: (int)point |
-(void) addPoint: (int)point |
166 |
{ |
{ |
167 |
_score += point; |
_score += point; |
168 |
|
|
169 |
|
[[NSNotificationCenter defaultCenter] |
170 |
|
postNotificationName:@"updatePlayer" object:self]; |
171 |
} |
} |
172 |
|
|
173 |
/** |
/** |
174 |
* Test the equivalence of the two players |
* Test the equivalence of the two players. |
175 |
*/ |
*/ |
176 |
- (BOOL) isEqualToPlayer: (HgPlayer *)player |
- (BOOL) isEqualToPlayer: (HgPlayer *)player |
177 |
{ |
{ |
203 |
HgGame *current = [HgGame currentGame]; |
HgGame *current = [HgGame currentGame]; |
204 |
HgPlayer *playerObject = [[current players] objectForKey: numIdent]; |
HgPlayer *playerObject = [[current players] objectForKey: numIdent]; |
205 |
|
|
206 |
printf ("current: %@, players : %@\n", current, [current players]); |
printf ("current: %@, players : %@, self : %@\n", current, [current players], |
207 |
|
self); |
208 |
|
|
209 |
if (playerObject != nil) |
if (playerObject != nil) |
210 |
{ |
{ |
220 |
|
|
221 |
if (self != nil) |
if (self != nil) |
222 |
{ |
{ |
223 |
ASSIGN (_name, [decoder decodeObject]); |
_name = RETAIN([decoder decodeObject]); |
224 |
ASSIGN (_userAtHost, [decoder decodeObject]); |
_userAtHost = RETAIN([decoder decodeObject]); |
225 |
ASSIGN (_team, [decoder decodeObject]); |
_team = RETAIN([decoder decodeObject]); |
226 |
ASSIGN (_ship, [decoder decodeObject]); |
_ship = RETAIN([decoder decodeObject]); |
227 |
[decoder decodeValueOfObjCType: "i" at: &_score]; |
[decoder decodeValueOfObjCType: "i" at: &_score]; |
228 |
} |
} |
229 |
|
|