/[hegemonie]/hegemonie/GameEngine/HgGame.m
ViewVC logotype

Diff of /hegemonie/GameEngine/HgGame.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13 by dam, Fri Aug 15 20:43:21 2003 UTC revision 1.14 by nicov, Mon Aug 18 10:28:30 2003 UTC
# Line 41  Line 41 
41   */   */
42  @implementation HgGame  @implementation HgGame
43    
44    static HgGame *_currentGame = nil;
45    
46    /**
47     * Return the current game in the current process.
48     */
49    + (HgGame *) currentGame
50    {
51      return _currentGame;
52    }
53    
54    
55  /**  /**
56   * Initialize a new game, with a given name.   * Initialize a new game, with a given name.
57     * Post an notification named "newGame" containing the game.
58   */   */
59  - (id) initWithName: (NSString *)name  - (id) initWithName: (NSString *)name
60  {  {
# Line 57  Line 69 
69        _teams = [[NSMutableDictionary alloc] init];        _teams = [[NSMutableDictionary alloc] init];
70        _map = nil;        _map = nil;
71        _objects = [[NSMutableDictionary alloc] init];        _objects = [[NSMutableDictionary alloc] init];
72          
73          _currentGame = self;
74      }      }
75        
76      [[NSNotificationCenter defaultCenter] postNotificationName: @"newGame"
77                                                          object: self];
78    
79    return self;    return self;
80  }  }
81    
# Line 67  Line 84 
84   */   */
85  - (void) dealloc  - (void) dealloc
86  {  {
87      _currentGame = nil;
88    
89    RELEASE(_name);    RELEASE(_name);
90    RELEASE(_players);    RELEASE(_players);
91    RELEASE(_teams);    RELEASE(_teams);
# Line 86  Line 105 
105    
106  /**  /**
107   * Add player to the current game. The player mustn't be already in game.   * Add player to the current game. The player mustn't be already in game.
108   * Post an notification named "addPlayer" containing the HgPlayer object.   * Post an notification named "addPlayer" containing the current game and
109     * the HgPlayer object.
110   */   */
111  - (void) addPlayer: (HgPlayer *)player  - (void) addPlayer: (HgPlayer *)player
112  {  {
# Line 97  Line 117 
117        
118    [_players setObject: player forKey: numId];    [_players setObject: player forKey: numId];
119    
120    [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"addPlayer"
121      postNotificationName: @"addPlayer" object: player];                                                        object: self
122                    userInfo: [NSDictionary dictionaryWithObject: player
123                                                          forKey: @"HgPlayer"]];
124  }  }
125    
126  /**  /**
127   * Remove player from the current game. The player must be contained in   * Remove player from the current game. The player must be contained in
128   * the game.   * the game.
129   * Post an notification named "removePlayer" containing the HgPlayer object.   * Post an notification named "removePlayer" containing the current game and
130     * HgPlayer object.
131   */   */
132  -(void)  removePlayer: (HgPlayer *)player  -(void)  removePlayer: (HgPlayer *)player
133  {  {
# Line 115  Line 138 
138    
139    [_players removeObjectForKey: numId];    [_players removeObjectForKey: numId];
140    
141    [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"removePlayer"
142      postNotificationName: @"removePlayer" object: player];                                                        object: self
143                    userInfo: [NSDictionary dictionaryWithObject: player
144                                                          forKey: @"HgPlayer"]];
145  }  }
146    
147  /**  /**
# Line 129  Line 154 
154    
155  /**  /**
156   * Add team to the current game. The team mustn't be already in game.   * Add team to the current game. The team mustn't be already in game.
157   * Post an notification named "addTeam" containing the HgTeam object.   * Post an notification named "addTeam" containing the current game and
158     * HgTeam object.
159   */   */
160  - (void) addTeam: (HgTeam *)team  - (void) addTeam: (HgTeam *)team
161  {  {
# Line 140  Line 166 
166    
167    [_teams setObject: team forKey: numId];    [_teams setObject: team forKey: numId];
168    
169    [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"addTeam"
170      postNotificationName: @"addTeam" object: team];                                                        object: self
171                    userInfo: [NSDictionary dictionaryWithObject: team
172                                                          forKey: @"HgTeam"]];
173  }  }
174    
175  /**  /**
176   * Remove team from the current game. The team must be contained in   * Remove team from the current game. The team must be contained in
177   * the game.   * the game.
178   * Post an notification named "removeTeam" containing the HgTeam object.   * Post an notification named "removeTeam" containing the current game and
179     * the HgTeam object.
180   */   */
181  - (void) removeTeam: (HgTeam *)team  - (void) removeTeam: (HgTeam *)team
182  {  {
# Line 158  Line 187 
187    
188    [_teams removeObjectForKey: numId];    [_teams removeObjectForKey: numId];
189    
190    [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"removeTeam"
191      postNotificationName: @"removeTeam" object: team];                                                        object: self
192                    userInfo: [NSDictionary dictionaryWithObject: team
193                                                          forKey: @"HgTeam"]];
194  }  }
195    
196  /**  /**
# Line 191  Line 222 
222    
223  /**  /**
224   * Add object to the current game. The object mustn't be already in game.   * Add object to the current game. The object mustn't be already in game.
225   * Post an notification named "addObject" containing the HgObject object.   * Post an notification named "addObject" containing the current game and
226     * HgObject object.
227   */   */
228  - (void) addObject: (HgObject *)object  - (void) addObject: (HgObject *)object
229  {  {
# Line 201  Line 233 
233    NSNumber *numId = [NSNumber numberWithInt: [object identifier]];    NSNumber *numId = [NSNumber numberWithInt: [object identifier]];
234    
235    [_objects setObject: object forKey: numId];    [_objects setObject: object forKey: numId];
236      
237   [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"addObject"
238     postNotificationName: @"addObject" object: object];                                                        object: self
239                    userInfo: [NSDictionary dictionaryWithObject: object
240                                                          forKey: @"HgObject"]];
241  }  }
242    
243  /**  /**
244   * Remove object from the current game. The object must be contained in   * Remove object from the current game. The object must be contained in
245   * the game.   * the game.
246   * Post an notification named "removeObject" containing the HgObject object.   * Post an notification named "removeObject" containing the current game and
247     * HgObject object.
248   */   */
249  - (void) removeObject: (HgObject *)object  - (void) removeObject: (HgObject *)object
250  {  {
# Line 220  Line 255 
255        
256    [_objects removeObjectForKey: numId];    [_objects removeObjectForKey: numId];
257    
258    [[NSNotificationCenter defaultCenter]    [[NSNotificationCenter defaultCenter] postNotificationName: @"removeObject"
259      postNotificationName: @"removeObject" object: object];                                                        object: self
260                    userInfo: [NSDictionary dictionaryWithObject: object
261                                                          forKey: @"HgObject"]];
262  }  }
263    
264  /**  /**
# Line 250  Line 287 
287    self = [super init];    self = [super init];
288    if (self != nil)    if (self != nil)
289      {      {
290          _currentGame = self;
291    
292        _name = RETAIN([decoder decodeObject]);        _name = RETAIN([decoder decodeObject]);
293        _players = RETAIN([decoder decodeObject]);        _players = RETAIN([decoder decodeObject]);
294        _teams = RETAIN([decoder decodeObject]);        _teams = RETAIN([decoder decodeObject]);

Legend:
Removed from v.1.13  
changed lines
  Added in v.1.14

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26