Développement XNA pour la XBox et le PC
254
l’expéditeur) connectés au serveur. Lorsque vous appuyez sur Q (ou le bouton Back dans
le cas de la manette), il ferme la connexion à la partie.
Exemple de dialogue entre client et serveur
public class Chapitre11_4 : Microsoft.Xna.Framework.Game
{
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
SpriteFont font;
NetworkSession session;
AvailableNetworkSessionCollection availableSessions;
PacketReader packetReader;
PacketWriter packetWriter;
string lastStringReceived = "";
public Chapitre11_4()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
Components.Add(new GamerServicesComponent(this));
}
protected override void Initialize()
{
base.Initialize();
packetReader = new PacketReader();
packetWriter = new PacketWriter();
}
protected override void LoadContent()
{
spriteBatch = new SpriteBatch(GraphicsDevice);
font = Content.Load("font");
}
protected override void Update(GameTime gameTime)
{
if ((Keyboard.GetState().IsKeyDown(Keys.Q) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.Back)) && session != null)
{
session.Dispose();
session = null;
availableSessions = null;
}
if ((Keyboard.GetState().IsKeyDown(Keys.C) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.A)) && session == null)
session = NetworkSession.Create(NetworkSessionType.SystemLink, 2, 31);
=Labat FM.book Page 254 Vendredi, 19. juin 2009 4:01 16
Précédent

- 275/366

Suivant