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=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..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 @@ -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,32 +229,59 @@ namespace CS_3505_Project_06 currentState = lobbyState.Welcome; ready = false; } - availableSessions = networkGame.FindSessions(); - if (availableSessions != null) + 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) { - networkGame.JoinSession(availableSessions[0]); - currentState = lobbyState.Connected; + 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; + availableSessions.Dispose(); + availableSessions = null; + } } - break; + + Console.WriteLine("Finding"); + 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(); } currentState = lobbyState.Welcome; + } 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 +295,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 +347,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 +371,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)