X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=c79b6a72d626a03520b2edc9d4ceb5b6ed72f271;hb=af55a699b4aac0663eea9dd5330505809e7f87e8;hp=3a7d8753afa18bb05eecb31d917148ca1d59d1bd;hpb=5284d2cf0e31870b5dab2e8ed9b9cb86313cbd2b;p=chaz%2Fcarfire diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs index 3a7d875..c79b6a7 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs @@ -149,22 +149,30 @@ namespace CS_3505_Project_06 { availableSessions = sessions; - if (availableSessions != null && availableSessions.Count > 0) - { - networkGame.JoinSession(availableSessions[0], JoinedSession); - currentState = lobbyState.JoiningGame; + //if (availableSessions != null && availableSessions.Count > 0) + //{ + // networkGame.JoinSession(availableSessions[0], JoinedSession); + // currentState = lobbyState.JoiningGame; + + // availableSessions.Dispose(); + // availableSessions = null; + //} + //else + //{ + // // TODO: This should do something more than just throw the player back to the welcome screen. + // currentState = lobbyState.Welcome; + // Console.WriteLine("No sessions to join!"); + //} + } - availableSessions.Dispose(); - availableSessions = null; - } - else - { - // TODO: This should do something more than just throw the player back to the welcome screen. - currentState = lobbyState.Welcome; - Console.WriteLine("No sessions to join!"); - } + // TODO: New method. + void AsyncCallbackFailed(Exception exception, NetworkGame networkGame) + { + currentState = lobbyState.Welcome; + Console.WriteLine("Exception as thrown during async call: " + exception.Message); } + public long Update(GameTime gameTime, NetworkGame networkGame) { @@ -210,6 +218,7 @@ namespace CS_3505_Project_06 if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y)) { currentState = lobbyState.JoiningGame; + networkGame.ErrorDelegate = AsyncCallbackFailed; networkGame.CreateSession(JoinedSession); } break; @@ -220,10 +229,43 @@ namespace CS_3505_Project_06 currentState = lobbyState.Welcome; ready = false; } + availableSessions = null; + networkGame.ErrorDelegate = AsyncCallbackFailed; networkGame.FindSessions(FoundSessions); currentState = lobbyState.FindingGames; break; + case lobbyState.FindingGames: + if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) + { + currentState = lobbyState.Welcome; + ready = false; + } + if (availableSessions != null && availableSessions.Count == 0) + currentState = lobbyState.FindGame; + else if (availableSessions != null && availableSessions.Count > 0) + { + if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1)) + { + networkGame.JoinSession(availableSessions[0], JoinedSession); + currentState = lobbyState.JoiningGame; + + availableSessions.Dispose(); + availableSessions = null; + } + if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2)) + { + networkGame.JoinSession(availableSessions[0], JoinedSession); + currentState = lobbyState.JoiningGame; + + availableSessions.Dispose(); + availableSessions = null; + } + } + + + Console.WriteLine("Finding"); + break; case lobbyState.Connected: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { @@ -234,6 +276,7 @@ namespace CS_3505_Project_06 networkGame.LeaveSession(); } currentState = lobbyState.Welcome; + } if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) networkGame.LocalGamer.IsReady = true;