When you have successfully joined or created a NetworkSession, the first thing you should do in your lobby is hook the following events:
NetworkSession.GamerJoined
NetworkSession.GamerLeft
NetworkSession.SessionEnded
NetworkSession.GameStarted
NetworkSession.StartGame()is called somewhere in your code. The advantage of using the start game function in your code is that the GameStarted event will be fired to each player. Letting you centralize any initialize anything you need to before the game starts.
NetworkSession.GameEnded
NetworkSession.EndGame(). Once again, allows you to transition the player to another state. The most likely scenario is changing to the lobby screen when this happens.
So, how do you hook these events? Its simple, lets take GameStarted for example:
// Assuming your NetworkSession is stored in CurrentSessionGot it? Good. Now you are ready to tackle the actual game logic! That will have to wait until another time though.
private void HookSessionEvents()
{
//hook all your events here, just using this one as an example
CurrentSession.GameStarted += CurrentSession_GameStartedHandler;
}
// change screen
private void gameStarted(object sender, GameStartedEventArgs e)
{
// Reset everything when we are starting a new game.
NetworkSession session = (NetworkSession)sender;
for (int i = 0; i < session.AllGamers.Count; i++)
{
GamerObject gOjbect = session.AllGamers[i].Tag as GamerObject;
gObject.Reset();
}
// show message on the screen for 3 seconds
ScreenManager.AddMessage("START THE GAME FOOL!", 3000);
// switch to your game screen / state here
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.