]> Dogcows Code - chaz/carfire/blobdiff - Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
Gui Finding
[chaz/carfire] / Project06 / CS 3505 Project 06 / CS 3505 Project 06 / LobbyGUI.cs
index 15d0955946f737d1709355648ec4cc7ac0d35b56..c79b6a72d626a03520b2edc9d4ceb5b6ed72f271 100644 (file)
@@ -66,6 +66,8 @@ namespace CS_3505_Project_06
             Welcome,\r
             CreateGame,\r
             FindGame,\r
+            FindingGames, // TODO: New state.\r
+            JoiningGame,  // TODO: New state.\r
             Connected\r
         }\r
 \r
@@ -127,13 +129,57 @@ namespace CS_3505_Project_06
             \r
         }\r
 \r
+        // TODO: New method.\r
+        void JoinedSession(NetworkSession session, NetworkGame networkGame)\r
+        {\r
+            if (session != null)\r
+            {\r
+                currentState = lobbyState.Connected;\r
+            }\r
+            else\r
+            {\r
+                // TODO: This should do something more than just throw the player back to the welcome screen.\r
+                currentState = lobbyState.Welcome;\r
+                Console.WriteLine("Couldn't create/join the session.");\r
+            }\r
+        }\r
+\r
+        // TODO: New method.\r
+        void FoundSessions(AvailableNetworkSessionCollection sessions, NetworkGame networkGame)\r
+        {\r
+            availableSessions = sessions;\r
+\r
+            //if (availableSessions != null && availableSessions.Count > 0)\r
+            //{\r
+            //    networkGame.JoinSession(availableSessions[0], JoinedSession);\r
+            //    currentState = lobbyState.JoiningGame;\r
+\r
+            //    availableSessions.Dispose();\r
+            //    availableSessions = null;\r
+            //}\r
+            //else\r
+            //{\r
+            //    // TODO: This should do something more than just throw the player back to the welcome screen.\r
+            //    currentState = lobbyState.Welcome;\r
+            //    Console.WriteLine("No sessions to join!");\r
+            //}\r
+        }\r
+\r
+        // TODO: New method.\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
+\r
         public long Update(GameTime gameTime, NetworkGame networkGame)\r
         {\r
             \r
             UpdateSpotLight(gameTime);\r
             currentKeyboardState = Keyboard.GetState();\r
 \r
-            if (networkGame.sessionExists())\r
+            if (networkGame.HasActiveSession)\r
             {\r
                 players = networkGame.NetworkGamers;\r
             }\r
@@ -163,7 +209,7 @@ namespace CS_3505_Project_06
                     {\r
                         currentState = lobbyState.Welcome;\r
                         ready = false;\r
-                        if (networkGame.sessionExists())\r
+                        if (networkGame.HasActiveSession)\r
                         {\r
                             players = null;\r
                             networkGame.LeaveSession();\r
@@ -171,8 +217,9 @@ namespace CS_3505_Project_06
                     }\r
                     if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y))\r
                     {\r
-                        currentState = lobbyState.Connected;\r
-                        networkGame.CreateSession(4);\r
+                        currentState = lobbyState.JoiningGame;\r
+                        networkGame.ErrorDelegate = AsyncCallbackFailed;\r
+                        networkGame.CreateSession(JoinedSession);\r
                     }   \r
                     break;\r
 \r
@@ -182,32 +229,59 @@ namespace CS_3505_Project_06
                         currentState = lobbyState.Welcome;\r
                         ready = false;\r
                     }\r
-                    availableSessions = networkGame.FindSessions();\r
-                    if (availableSessions != null)\r
+                    availableSessions = null;\r
+                    networkGame.ErrorDelegate = AsyncCallbackFailed;\r
+                    networkGame.FindSessions(FoundSessions);\r
+                    currentState = lobbyState.FindingGames;\r
+                    break;\r
+\r
+                case lobbyState.FindingGames:\r
+                    if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                    {\r
+                        currentState = lobbyState.Welcome;\r
+                        ready = false;\r
+                    }\r
+                    if (availableSessions != null && availableSessions.Count == 0)\r
+                        currentState = lobbyState.FindGame;\r
+                    else if (availableSessions != null && availableSessions.Count > 0)\r
                     {\r
-                        networkGame.JoinSession(availableSessions[0]);\r
-                        currentState = lobbyState.Connected;\r
+                        if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1))\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
+                        {\r
+                            networkGame.JoinSession(availableSessions[0], JoinedSession);\r
+                            currentState = lobbyState.JoiningGame;\r
 \r
-                        availableSessions.Dispose();\r
-                        availableSessions = null;\r
+                            availableSessions.Dispose();\r
+                            availableSessions = null;\r
+                        }\r
                     }\r
-                    break;\r
 \r
+\r
+                    Console.WriteLine("Finding");\r
+                    break;\r
                 case lobbyState.Connected:\r
                     if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
                     {\r
                         ready = false;\r
-                        if (networkGame.sessionExists())\r
+                        if (networkGame.HasActiveSession)\r
                         {\r
                             players = null;\r
                             networkGame.LeaveSession();\r
                         }\r
                         currentState = lobbyState.Welcome;\r
+                \r
                     }\r
                     if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))\r
                         networkGame.LocalGamer.IsReady = true;\r
 \r
-                    if (networkGame.sessionExists())\r
+                    if (networkGame.HasActiveSession)\r
                     {\r
                         localPlayer = networkGame.LocalGamer;\r
                         players = networkGame.NetworkGamers;\r
@@ -221,6 +295,15 @@ namespace CS_3505_Project_06
                                     break;\r
                                 }\r
                         }\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
+                        {\r
+                            if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B))\r
+                            {\r
+                                networkGame.ForceStartGame();\r
+                            }\r
+                        }\r
                     }\r
                     else\r
                         currentState = lobbyState.Welcome;\r
@@ -264,7 +347,7 @@ namespace CS_3505_Project_06
 \r
                     break;\r
 \r
-                case lobbyState.FindGame:\r
+                case lobbyState.FindingGames:\r
                     spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);\r
                     if(availableSessions == null)\r
                         spriteBatch.DrawString(menuFont, "searching for available games ....", new Vector2(150, 100), Color.Gray, 0f, zero, .7f, SpriteEffects.None, 0.5f);\r
@@ -288,7 +371,7 @@ namespace CS_3505_Project_06
 \r
                 case lobbyState.Connected:\r
                     DrawPlayerList(spriteBatch);\r
-                    \r
+                                        \r
                     if(allReady && players.Count == 2 && 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
This page took 0.026536 seconds and 4 git commands to generate.