X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=78ee37b7a9912c9dad0ebf700bf7b83be60d9dd7;hb=87550d29aa4aa52e9c3e413e58877b494d7d7017;hp=15d0955946f737d1709355648ec4cc7ac0d35b56;hpb=4ac7a5127df67229deb64907208ff78dc3869aac;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 15d0955..78ee37b 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 @@ -66,6 +66,8 @@ namespace CS_3505_Project_06 Welcome, CreateGame, FindGame, + FindingGames, // TODO: New state. + JoiningGame, // TODO: New state. Connected } @@ -127,13 +129,57 @@ namespace CS_3505_Project_06 } + // TODO: New method. + void JoinedSession(NetworkSession session, NetworkGame networkGame) + { + if (session != null) + { + currentState = lobbyState.Connected; + } + else + { + // TODO: This should do something more than just throw the player back to the welcome screen. + currentState = lobbyState.Welcome; + Console.WriteLine("Couldn't create/join the session."); + } + } + + // TODO: New method. + void FoundSessions(AvailableNetworkSessionCollection sessions, NetworkGame networkGame) + { + availableSessions = sessions; + + 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!"); + } + } + + // 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) { UpdateSpotLight(gameTime); currentKeyboardState = Keyboard.GetState(); - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { players = networkGame.NetworkGamers; } @@ -163,7 +209,7 @@ namespace CS_3505_Project_06 { currentState = lobbyState.Welcome; ready = false; - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { players = null; networkGame.LeaveSession(); @@ -171,8 +217,9 @@ namespace CS_3505_Project_06 } if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y)) { - currentState = lobbyState.Connected; - networkGame.CreateSession(4); + currentState = lobbyState.JoiningGame; + networkGame.ErrorDelegate = AsyncCallbackFailed; + networkGame.CreateSession(JoinedSession); } break; @@ -182,22 +229,16 @@ namespace CS_3505_Project_06 currentState = lobbyState.Welcome; ready = false; } - availableSessions = networkGame.FindSessions(); - if (availableSessions != null) - { - networkGame.JoinSession(availableSessions[0]); - currentState = lobbyState.Connected; - - availableSessions.Dispose(); - availableSessions = null; - } + networkGame.ErrorDelegate = AsyncCallbackFailed; + networkGame.FindSessions(FoundSessions); + currentState = lobbyState.FindingGames; break; case lobbyState.Connected: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { ready = false; - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { players = null; networkGame.LeaveSession(); @@ -207,7 +248,7 @@ namespace CS_3505_Project_06 if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) networkGame.LocalGamer.IsReady = true; - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { localPlayer = networkGame.LocalGamer; players = networkGame.NetworkGamers; @@ -221,6 +262,15 @@ namespace CS_3505_Project_06 break; } } + + //allows host to start the game when all players are ready, change count below to different number for testing with less then 4 players + if(allReady && players.Count == 2 && localPlayer == players[0]) + { + if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B)) + { + networkGame.ForceStartGame(); + } + } } else currentState = lobbyState.Welcome; @@ -264,7 +314,7 @@ namespace CS_3505_Project_06 break; - case lobbyState.FindGame: + case lobbyState.FindingGames: spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0); if(availableSessions == null) spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f); @@ -288,7 +338,7 @@ namespace CS_3505_Project_06 case lobbyState.Connected: DrawPlayerList(spriteBatch); - + if(allReady && players.Count == 2 && localPlayer == players[0]) spriteBatch.DrawString(menuFont, "Press B to begin game!", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f); else if(allReady)