Le mode multijoueur
CHAPITRE 11
255
if ((Keyboard.GetState().IsKeyDown(Keys.S) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.B)) &&
➥SignedInGamer.SignedInGamers.Count != 0 && session == null)
{
availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink,
➥2, null);
if (availableSessions != null && availableSessions.Count > 0)
session = NetworkSession.Join(availableSessions[0]);
}
if ((Keyboard.GetState().IsKeyDown(Keys.M) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.Y)) && session != null)
{
packetWriter.Write(DateTime.Now.ToString());
session.LocalGamers[0].SendData(packetWriter, SendDataOptions.);
}
if (session != null)
{
session.Update();
LocalNetworkGamer gamer = session.LocalGamers[0];
if (gamer.IsDataAvailable)
{
NetworkGamer sender;
gamer.ReceiveData(packetReader, out sender);
if (gamer != sender)
lastStringReceived = packetReader.ReadString();
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
if (session != null)
{
if (session.IsHost)
spriteBatch.DrawString(font, "Serveur (" + SignedInGamer
➥.SignedInGamers[0].Gamertag + ")", new Vector2(100, 100),
➥Color.White);
else
spriteBatch.DrawString(font, "Client (" + SignedInGamer
➥.SignedInGamers[0].Gamertag + ") connecte sur " +
➥session.Host.ToString() , new Vector2(100, 100), Color.White);
=Labat FM.book Page 255 Vendredi, 19. juin 2009 4:01 16
CHAPITRE 11
255
if ((Keyboard.GetState().IsKeyDown(Keys.S) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.B)) &&
➥SignedInGamer.SignedInGamers.Count != 0 && session == null)
{
availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink,
➥2, null);
if (availableSessions != null && availableSessions.Count > 0)
session = NetworkSession.Join(availableSessions[0]);
}
if ((Keyboard.GetState().IsKeyDown(Keys.M) || GamePad.GetState
➥(PlayerIndex.One).IsButtonDown(Buttons.Y)) && session != null)
{
packetWriter.Write(DateTime.Now.ToString());
session.LocalGamers[0].SendData(packetWriter, SendDataOptions.);
}
if (session != null)
{
session.Update();
LocalNetworkGamer gamer = session.LocalGamers[0];
if (gamer.IsDataAvailable)
{
NetworkGamer sender;
gamer.ReceiveData(packetReader, out sender);
if (gamer != sender)
lastStringReceived = packetReader.ReadString();
}
}
base.Update(gameTime);
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.CornflowerBlue);
spriteBatch.Begin();
if (session != null)
{
if (session.IsHost)
spriteBatch.DrawString(font, "Serveur (" + SignedInGamer
➥.SignedInGamers[0].Gamertag + ")", new Vector2(100, 100),
➥Color.White);
else
spriteBatch.DrawString(font, "Client (" + SignedInGamer
➥.SignedInGamers[0].Gamertag + ") connecte sur " +
➥session.Host.ToString() , new Vector2(100, 100), Color.White);
=Labat FM.book Page 255 Vendredi, 19. juin 2009 4:01 16
