X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=8f45156c015f8a770669d0a8ed35b5b0feecc83f;hb=775a5b88d6eca31edc79446cd43c2ae292197931;hp=6eaaf1892f4fbcdb45401f5001a398be0bec3159;hpb=d9616289a57884beaed219a583076cf910810e2d;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 6eaaf18..8f45156 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 @@ -14,6 +14,7 @@ namespace CS_3505_Project_06 { public class lobbyGUI : ILobby { + #region local variables float scale; Texture2D background; @@ -65,6 +66,8 @@ namespace CS_3505_Project_06 String chatMessage; Queue currentChat; + + private enum lobbyState { Welcome, @@ -76,6 +79,7 @@ namespace CS_3505_Project_06 } lobbyState currentState; + #endregion public lobbyGUI() { @@ -136,7 +140,9 @@ namespace CS_3505_Project_06 } - // TODO: New method. + /// + /// Transition into connected state + /// void JoinedSession(NetworkSession session, NetworkGame networkGame) { if (session != null) @@ -151,19 +157,26 @@ namespace CS_3505_Project_06 } } - // TODO: New method. + /// + /// Called when Async FindSession returns. Available sessions is then updated + /// void FoundSessions(AvailableNetworkSessionCollection sessions, NetworkGame networkGame) { availableSessions = sessions; } - // TODO: New method. + /// + /// Catches exceptions for and Async calls + /// void AsyncCallbackFailed(Exception exception, NetworkGame networkGame) { currentState = lobbyState.Welcome; Console.WriteLine("Exception as thrown during async call: " + exception.Message); } + /// + /// Adds and new chats to the chat list. If chat list is full, older messages are removed. + /// private void UpdateChat(GameTime gameTime, NetworkGame networkGame) { List chts = networkGame.ReceiveChats(); @@ -181,6 +194,9 @@ namespace CS_3505_Project_06 } + /// + /// Main update call for Lobby, what is actually updated is determined by what the current state is. + /// public long Update(GameTime gameTime, NetworkGame networkGame) { @@ -253,22 +269,27 @@ namespace CS_3505_Project_06 currentState = lobbyState.FindGame; else if (availableSessions != null && availableSessions.Count > 0) { - if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1)) + if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1) && availableSessions.Count > 0) { networkGame.JoinSession(availableSessions[0], JoinedSession); - currentState = lobbyState.JoiningGame; - - availableSessions.Dispose(); - availableSessions = null; } - if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2)) + else if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2) && availableSessions.Count > 1) { - networkGame.JoinSession(availableSessions[0], JoinedSession); - currentState = lobbyState.JoiningGame; - - availableSessions.Dispose(); - availableSessions = null; + networkGame.JoinSession(availableSessions[1], JoinedSession); } + else if (currentKeyboardState.IsKeyDown(Keys.D3) && previousKeyboardState.IsKeyUp(Keys.D3) && availableSessions.Count > 2) + { + networkGame.JoinSession(availableSessions[2], JoinedSession); + } + else if (currentKeyboardState.IsKeyDown(Keys.D4) && previousKeyboardState.IsKeyUp(Keys.D4) && availableSessions.Count > 3) + { + networkGame.JoinSession(availableSessions[3], JoinedSession); + } + + currentState = lobbyState.JoiningGame; + + availableSessions.Dispose(); + availableSessions = null; } break; @@ -310,7 +331,7 @@ namespace CS_3505_Project_06 } } - else + else //normal op mode { UpdateChat(gameTime, networkGame); chatMessage = ""; @@ -349,7 +370,7 @@ namespace CS_3505_Project_06 } //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 (allReady && players.Count == 4 && localPlayer == players[0]) { if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B)) { @@ -425,7 +446,7 @@ namespace CS_3505_Project_06 case lobbyState.Connected: DrawPlayerList(spriteBatch); DrawChatInfo(spriteBatch); - if(allReady && players.Count == 2 && localPlayer == players[0]) + if(allReady && players.Count == 4 && 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) spriteBatch.DrawString(menuFont, "The game will begin soon.", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f); @@ -437,6 +458,9 @@ namespace CS_3505_Project_06 return 1; } + /// + /// Updates backgound animation with moving spotlight. Spotlight bounces off walls + /// private void UpdateSpotLight(GameTime gameTime) { spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds, @@ -452,6 +476,9 @@ namespace CS_3505_Project_06 } } + /// + /// Draws the list of current chat messages received by the local client. + /// private void DrawChatInfo(SpriteBatch spriteBatch) { if (currentChat.Count > 0) @@ -467,6 +494,9 @@ namespace CS_3505_Project_06 spriteBatch.DrawString(menuFont, chatMessage, new Vector2(400, 10 + 15*(currentChat.Count + 1)), Color.Green, 0f, zero, .6f, SpriteEffects.None, 1f); } + /// + /// Draws player list objects for the connected state. + /// private void DrawPlayerList(SpriteBatch spriteBatch) {