Figure 6-2. The network game scene in Font

Drawing PDF-417 2d barcode in Font Figure 6-2. The network game scene

Figure 6-2. The network game scene
Generating PDF-417 2d Barcode In None
Using Barcode generation for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Generating DataMatrix In None
Using Barcode generator for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
www.OnBarcode.com
Controlling the Input to the Scene
EAN13 Maker In None
Using Barcode generation for Font Control to generate, create European Article Number 13 image in Font applications.
www.OnBarcode.com
Barcode Creation In None
Using Barcode generator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
The HandleNetworkSceneInput method deals with all input originating from the menu for this scene: /// <summary> /// Handle Network Scene menu /// </summary> private void HandleNetworkSceneInput() { if (CheckEnterA()) { audio.MenuSelect.Play(); if (Gamer.SignedInGamers.Count == 0) { HandleNotSigned(); }
UPC Code Maker In None
Using Barcode encoder for Font Control to generate, create UPC-A Supplement 2 image in Font applications.
www.OnBarcode.com
Code 39 Full ASCII Generation In None
Using Barcode generation for Font Control to generate, create Code 3 of 9 image in Font applications.
www.OnBarcode.com
CHAPTER 6 ROCK RAIN LIVE!
Barcode Encoder In None
Using Barcode drawer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Encode USPS Intelligent Mail In None
Using Barcode drawer for Font Control to generate, create USPS OneCode Solution Barcode image in Font applications.
www.OnBarcode.com
else { HandleSigned(); } } } This code separates the menu treatment for two distinct situations: when the user is connected and when the user is not connected to the network. The HandleNotSigned method contains all the code for the menu when it s showing the options for a not-connected player, and the HandleSigned method contains the options for a connected user. All that an unconnected user can do is connect to the network or go back to the initial scene. So, the HandleNotSigned method is simple: /// <summary> /// Handle network scene menu for an unconnected user /// </summary> private void HandleNotSigned() { switch (networkScene.SelectedMenuIndex) { case 0: if (!Guide.IsVisible) { Guide.ShowSignIn(1, false); break; } break; case 1: ShowScene(startScene); break; } } On the other hand, a user who is connected to the network can create a new game, join an already created session, change the authenticated user, or go back to the initial scene. If this connected user is creating a game, the user can also cancel the wait for the other player. You implement these situations in the HandleSigned method, as follows: /// <summary> /// Handle network scene menu for a connected user /// </summary> private void HandleSigned() { switch (networkScene.State) { case NetworkScene.NetworkGameState.idle: switch (networkScene.SelectedMenuIndex) {
Decoding PDF 417 In Visual C#.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
PDF417 Printer In VS .NET
Using Barcode encoder for Reporting Service Control to generate, create PDF 417 image in Reporting Service applications.
www.OnBarcode.com
CHAPTER 6 ROCK RAIN LIVE!
Denso QR Bar Code Creator In Java
Using Barcode creation for Android Control to generate, create Quick Response Code image in Android applications.
www.OnBarcode.com
Barcode Generation In Java
Using Barcode maker for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
case 0: // Join a network game JoinSession(); break; case 1: // Create a network game CreateSession(); break; case 2: // Show the guide to change user if (!Guide.IsVisible) { Guide.ShowSignIn(1, false); break; } break; case 3: // Back to start scene ShowScene(startScene); break; } break; case NetworkScene.NetworkGameState.creating: // Close the session created CloseSession(); // Wait for a new command networkScene.State = NetworkScene.NetworkGameState.idle; networkScene.Message = ""; break; } } The CreateSession, JoinSession, and CloseSession methods are common to all network games. They start and end all the communication between the players. You ll implement them soon, but let s first create a class to help you with the network services necessary for Rock Rain Live.
Barcode Reader In Java
Using Barcode Control SDK for Eclipse BIRT Control to generate, create, read, scan barcode image in BIRT applications.
www.OnBarcode.com
Code-39 Maker In Visual Studio .NET
Using Barcode creation for Reporting Service Control to generate, create ANSI/AIM Code 39 image in Reporting Service applications.
www.OnBarcode.com
Creating the NetworkHelper Class
Create EAN 128 In Java
Using Barcode creator for BIRT Control to generate, create EAN 128 image in BIRT applications.
www.OnBarcode.com
Encode EAN-13 Supplement 5 In Objective-C
Using Barcode printer for iPhone Control to generate, create GTIN - 13 image in iPhone applications.
www.OnBarcode.com
You saw in the previous chapter that all the network services in your XNA game are centralized in the NetworkSession class. With it, you use objects from the PacketWriter and PacketReader classes to write and read network data. For organizational purposes, you ll create a class that encapsulates all the necessary data transport functionality, using these classes, so that you have only one object you can use to send and read data from the server and the client, and to the server and the client. This class is simple just add a new class called NetworkHelper to the project, and add the following code:
Recognizing Data Matrix ECC200 In Visual Basic .NET
Using Barcode recognizer for .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Generate UPC Code In Java
Using Barcode creator for Java Control to generate, create UPC-A Supplement 2 image in Java applications.
www.OnBarcode.com
CHAPTER 6 ROCK RAIN LIVE!
Painting PDF-417 2d Barcode In None
Using Barcode generation for Online Control to generate, create PDF417 image in Online applications.
www.OnBarcode.com
EAN 13 Encoder In Visual Basic .NET
Using Barcode creator for Visual Studio .NET Control to generate, create EAN-13 image in .NET applications.
www.OnBarcode.com
using Microsoft.Xna.Framework.Net; namespace RockRainLive { /// <summary> /// Helper for network services /// </summary> class NetworkHelper { // Network stuff private NetworkSession networkSession; private readonly PacketWriter serverPacketWriter private readonly PacketReader serverPacketReader private readonly PacketWriter clientPacketWriter private readonly PacketReader clientPacketReader /// <summary> /// The active network session /// </summary> public NetworkSession NetworkGameSession { get { return networkSession; } set { networkSession = value; } } /// <summary> /// Writer for the server data /// </summary> public PacketWriter ServerPacketWriter { get { return serverPacketWriter; } } /// <summary> /// Writer for the client data /// </summary> public PacketWriter ClientPacketWriter { get { return clientPacketWriter; } }
= = = =
new new new new
PacketWriter(); PacketReader(); PacketWriter(); PacketReader();
CHAPTER 6 ROCK RAIN LIVE!
/// <summary> /// Reader for the client data /// </summary> public PacketReader ClientPacketReader { get { return clientPacketReader; } } /// <summary> /// Reader for the server data /// </summary> public PacketReader ServerPacketReader { get { return serverPacketReader; } } /// <summary> /// Send all server data /// </summary> public void SendServerData() { if (ServerPacketWriter.Length > 0) { // Send the combined data to everyone in the session. LocalNetworkGamer server = (LocalNetworkGamer) networkSession.Host; server.SendData(ServerPacketWriter, SendDataOptions.InOrder); } } /// <summary> /// Read server data /// </summary> public NetworkGamer ReadServerData(LocalNetworkGamer gamer) { NetworkGamer sender; // Read a single packet from the network. gamer.ReceiveData(ServerPacketReader, out sender); return sender; }
CHAPTER 6 ROCK RAIN LIVE!
/// <summary> /// Send all client data /// </summary> public void SendClientData() { if (ClientPacketWriter.Length > 0) { // The first player is always running in the server... networkSession.LocalGamers[0].SendData(clientPacketWriter, SendDataOptions.InOrder, networkSession.Host); } } /// <summary> /// Read the client data /// </summary> public NetworkGamer ReadClientData(LocalNetworkGamer gamer) { NetworkGamer sender; // Read a single packet from the network. gamer.ReceiveData(ClientPacketReader, out sender); return sender; } } } This class contains your NetworkSession object, as well as methods to send and read the data packages through the PacketWriter and PacketReader objects, both for the client and for the server. You ll use this class to implement your communication protocol in the next section. For now, you ll initialize the NetworkSession object of this class, as you did in the previous chapter, to create a game session, join an existing session, or terminate a session; that is, you ll implement the CreateSession, JoinSession, and CloseSession methods that we mentioned earlier in the chapter.
Copyright © OnBarcode.com . All rights reserved.