X-Git-Url: https://git.brokenzipper.com/gitweb?a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=3a7d8753afa18bb05eecb31d917148ca1d59d1bd;hb=9187849a37e447f2440ef8257e15e8652f0c51e8;hp=6026a6161d212a66a88a77f68de109369bf394c3;hpb=8a11d454e88649b469fb9794f662beb7f6a15c6a;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 6026a61..3a7d875 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,49 @@ 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!"); + } + } + public long Update(GameTime gameTime, NetworkGame networkGame) { UpdateSpotLight(gameTime); currentKeyboardState = Keyboard.GetState(); - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { players = networkGame.NetworkGamers; } @@ -163,7 +201,7 @@ namespace CS_3505_Project_06 { currentState = lobbyState.Welcome; ready = false; - if (networkGame.sessionExists()) + if (networkGame.HasActiveSession) { players = null; networkGame.LeaveSession(); @@ -171,8 +209,8 @@ namespace CS_3505_Project_06 } if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y)) { - currentState = lobbyState.Connected; - networkGame.CreateSession(4); + currentState = lobbyState.JoiningGame; + networkGame.CreateSession(JoinedSession); } break; @@ -182,22 +220,15 @@ 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.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 +238,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,11 +252,13 @@ 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.StartGame(); + networkGame.ForceStartGame(); } } } @@ -271,7 +304,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);