Game Development Reference
In-Depth Information
4. As
restartGameAfterSomeTime
is used at the time of sending and receiv-
ing the packet, let us write this method as shown in the following code:
- (void)restartGameAfterSomeTime
{
[NSTimer scheduledTimerWithTimeInterval:2.0
target:self
selector:@selector(restartGame)
userInfo:nil
repeats:NO];
}
- (void)restartGame
{
gameUniqueIdForPlayerAllocation = arc4random();
self.gameState = kGameStatePlayerToConnect;
self.gameInfoLabel.text = kConnectingDevicesText;
[self resetLocalTanksAndInfoToInitialState];
}
5. In this method, a
NSTimer
of 2.0 seconds will be triggered, calling a function
restartGame
in which, again, the
gameUniqueIdFoPlayerAlloca-
tion
will be generated, the game state set to
kGameStatePlayerToCon-
nect
, and the label text changed to
Tap to connect
. For visual initial state, we
call the method
resetLocalTanksAndInfoToInitialState
in which
the local data structure and the visual attributes of tanks are set.
6. Whenever the game completes the
restartGameAfterSomeTime
method is
called, on both local and remote devices, to set the initial state of game and it
looks like this: