]> Dogcows Code - chaz/carfire/blobdiff - Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
fixed bug where the 'push b to begin' message wasn't displaying for the host at the...
[chaz/carfire] / Project06 / CS 3505 Project 06 / CS 3505 Project 06 / LobbyGUI.cs
index 6eaaf1892f4fbcdb45401f5001a398be0bec3159..8f45156c015f8a770669d0a8ed35b5b0feecc83f 100644 (file)
@@ -14,6 +14,7 @@ namespace CS_3505_Project_06
 {\r
     public class lobbyGUI : ILobby\r
     {\r
+        #region local variables\r
         float scale;\r
 \r
         Texture2D background;\r
@@ -65,6 +66,8 @@ namespace CS_3505_Project_06
         String chatMessage;\r
         Queue<ChatInfo> currentChat;\r
 \r
+        \r
+\r
         private enum lobbyState\r
         {\r
             Welcome,\r
@@ -76,6 +79,7 @@ namespace CS_3505_Project_06
         }\r
 \r
         lobbyState currentState;\r
+        #endregion\r
 \r
         public lobbyGUI()\r
         {\r
@@ -136,7 +140,9 @@ namespace CS_3505_Project_06
             \r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Transition into connected state\r
+        /// </summary>\r
         void JoinedSession(NetworkSession session, NetworkGame networkGame)\r
         {\r
             if (session != null)\r
@@ -151,19 +157,26 @@ namespace CS_3505_Project_06
             }\r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Called when Async FindSession returns. Available sessions is then updated\r
+        /// </summary>\r
         void FoundSessions(AvailableNetworkSessionCollection sessions, NetworkGame networkGame)\r
         {\r
             availableSessions = sessions;\r
         }\r
 \r
-        // TODO: New method.\r
+        /// <summary>\r
+        /// Catches exceptions for and Async calls\r
+        /// </summary>\r
         void AsyncCallbackFailed(Exception exception, NetworkGame networkGame)\r
         {\r
             currentState = lobbyState.Welcome;\r
             Console.WriteLine("Exception as thrown during async call: " + exception.Message);\r
         }\r
 \r
+        /// <summary>\r
+        /// Adds and new chats to the chat list. If chat list is full, older messages are removed.\r
+        /// </summary>\r
         private void UpdateChat(GameTime gameTime, NetworkGame networkGame)\r
         {\r
             List<ChatInfo> chts = networkGame.ReceiveChats();\r
@@ -181,6 +194,9 @@ namespace CS_3505_Project_06
 \r
         }\r
 \r
+        /// <summary>\r
+        /// Main update call for Lobby, what is actually updated is determined by what the current state is.\r
+        /// </summary>\r
         public long Update(GameTime gameTime, NetworkGame networkGame)\r
         {\r
             \r
@@ -253,22 +269,27 @@ namespace CS_3505_Project_06
                         currentState = lobbyState.FindGame;\r
                     else if (availableSessions != null && availableSessions.Count > 0)\r
                     {\r
-                        if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1))\r
+                        if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1) && availableSessions.Count > 0)\r
                         {\r
                             networkGame.JoinSession(availableSessions[0], JoinedSession);\r
-                            currentState = lobbyState.JoiningGame;\r
-\r
-                            availableSessions.Dispose();\r
-                            availableSessions = null;\r
                         }\r
-                        if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2))\r
+                        else if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2) && availableSessions.Count > 1)\r
                         {\r
-                            networkGame.JoinSession(availableSessions[0], JoinedSession);\r
-                            currentState = lobbyState.JoiningGame;\r
-\r
-                            availableSessions.Dispose();\r
-                            availableSessions = null;\r
+                            networkGame.JoinSession(availableSessions[1], JoinedSession);\r
                         }\r
+                        else if (currentKeyboardState.IsKeyDown(Keys.D3) && previousKeyboardState.IsKeyUp(Keys.D3) && availableSessions.Count > 2)\r
+                        {\r
+                            networkGame.JoinSession(availableSessions[2], JoinedSession);\r
+                        }\r
+                        else if (currentKeyboardState.IsKeyDown(Keys.D4) && previousKeyboardState.IsKeyUp(Keys.D4) && availableSessions.Count > 3)\r
+                        {\r
+                            networkGame.JoinSession(availableSessions[3], JoinedSession);\r
+                        }\r
+\r
+                        currentState = lobbyState.JoiningGame;\r
+\r
+                        availableSessions.Dispose();\r
+                        availableSessions = null;\r
                     }\r
 \r
                     break;\r
@@ -310,7 +331,7 @@ namespace CS_3505_Project_06
                         }\r
                         \r
                     }\r
-                    else\r
+                    else  //normal op mode\r
                     {\r
                         UpdateChat(gameTime, networkGame);\r
                         chatMessage = "";\r
@@ -349,7 +370,7 @@ namespace CS_3505_Project_06
                             }\r
 \r
                             //allows host to start the game when all players are ready, change count below to different number for testing with less then 4 players\r
-                            if (allReady && players.Count == 2 && localPlayer == players[0])\r
+                            if (allReady && players.Count == 4 && localPlayer == players[0])\r
                             {\r
                                 if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B))\r
                                 {\r
@@ -425,7 +446,7 @@ namespace CS_3505_Project_06
                 case lobbyState.Connected:\r
                     DrawPlayerList(spriteBatch);\r
                     DrawChatInfo(spriteBatch);                    \r
-                    if(allReady && players.Count == 2 && localPlayer == players[0])\r
+                    if(allReady && players.Count == 4 && localPlayer == players[0])\r
                         spriteBatch.DrawString(menuFont, "Press B to begin game!", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
                     else if(allReady)\r
                         spriteBatch.DrawString(menuFont, "The game will begin soon.", new Vector2(MaxX / 2, MaxY / 2), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
@@ -437,6 +458,9 @@ namespace CS_3505_Project_06
             return 1;\r
         }\r
 \r
+        /// <summary>\r
+        /// Updates backgound animation with moving spotlight. Spotlight bounces off walls \r
+        /// </summary>\r
         private void UpdateSpotLight(GameTime gameTime)\r
         {\r
             spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,\r
@@ -452,6 +476,9 @@ namespace CS_3505_Project_06
             }\r
         }\r
 \r
+        /// <summary>\r
+        /// Draws the list of current chat messages received by the local client.\r
+        /// </summary>\r
         private void DrawChatInfo(SpriteBatch spriteBatch)\r
         {\r
             if (currentChat.Count > 0)\r
@@ -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);\r
         }\r
 \r
+        /// <summary>\r
+        /// Draws player list objects for the connected state.\r
+        /// </summary>\r
         private void DrawPlayerList(SpriteBatch spriteBatch)\r
         {\r
             \r
This page took 0.026266 seconds and 4 git commands to generate.