Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Một vài giây sau đó, bằng cách thông báo cho biết kết quả của tìm kiếm phiên. Bây giờ mà bạn có hai máy với ký kết, trong các game thủ, những một trong đầu tiên tạo ra một phiên họp và làm một máy chủ, và một trong các thứ hai tham gia các phiên tạo ra, nó là thời gian để thông báo XNA rằng bạn đang sẵn sàng để đi, và bắt đầu trò chơi! | 154 CHAPTER 5 BASICS OF GAME NETWORKING All you need to do now is to revise the Update method of the Gamel class to call the new asynchronous session-finding method by including the following lines Find a session asynchronously if Keyboard.GetState .IsKeyDown Keys.F4 networkHelper.AsyncFindSession You can test the new code by executing again the steps you used in the previous section to join a session synchronously except that you press the F4 key instead of the F3 one. On the client machine you ll see the message Asynchronous search started followed a few seconds later by the message that states the result of the session searching. Now that you have two machines with signed-in gamers the first one creating a session and acting as a host and the second one joining the session created it s time to inform XNA that you are ready to go and start the game Starting the Game A game session in XNA has three possible states informed by its SessionState property NetworkSessionState.Lobby A session in this state means that the local machine has joined a session and is ready to start but is waiting for other players to join and the host to start the game. The host knows when all players are ready by checking the IsEveryoneReady property of the session object it can check the number of signed-in gamers by consulting Gamer.SignedInGamers.Count. NetworkSessionState.Playing When the host starts the game by calling the StartGame method of the session object the GameStarted session event is fired for all players and the session state changes from Lobby to Playing. NetworkSessionState.Ended Similarly the host calls the EndGame method of the session object to finish a game firing the GameEnded session event for all players and changing the session state from Playing to Ended. So once you have all players connected in the same session you need every player to report that he or she is ready and to include the code in the host to start and end the game. Signaling that all local players .