]> Dogcows Code - chaz/carfire/commitdiff
Chat Started
authorbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Wed, 31 Mar 2010 06:27:34 +0000 (06:27 +0000)
committerbrady <brady@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Wed, 31 Mar 2010 06:27:34 +0000 (06:27 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@44 92bb83a3-7c8f-8a45-bc97-515c4e399668

Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs

index c79b6a72d626a03520b2edc9d4ceb5b6ed72f271..e580b0402dc193144438a45a10b081bfbbeaf583 100644 (file)
@@ -61,6 +61,10 @@ namespace CS_3505_Project_06
 \r
         int selectedSessionIndex;\r
 \r
+        bool chatActive;\r
+        String chatMessage;\r
+        Queue<ChatInfo> currentChat;\r
+\r
         private enum lobbyState\r
         {\r
             Welcome,\r
@@ -78,6 +82,9 @@ namespace CS_3505_Project_06
             currentState = lobbyState.Welcome;\r
             selectedSessionIndex = 0;\r
             ready = false;\r
+            chatActive = false;\r
+            chatMessage = "";\r
+            currentChat = new Queue<ChatMessage>();\r
         }\r
 \r
         public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
@@ -148,21 +155,6 @@ namespace CS_3505_Project_06
         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
@@ -172,6 +164,11 @@ namespace CS_3505_Project_06
             Console.WriteLine("Exception as thrown during async call: " + exception.Message);\r
         }\r
 \r
+        private void UpdateChat(GameTime gameTime, NetworkGame networkGame)\r
+        {\r
+            currentChat.Concat(networkGame.ReceiveChats);\r
+\r
+        }\r
 \r
         public long Update(GameTime gameTime, NetworkGame networkGame)\r
         {\r
@@ -267,47 +264,84 @@ namespace CS_3505_Project_06
                     Console.WriteLine("Finding");\r
                     break;\r
                 case lobbyState.Connected:\r
-                    if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                    if (chatActive)\r
                     {\r
-                        ready = false;\r
-                        if (networkGame.HasActiveSession)\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
                         {\r
-                            players = null;\r
-                            networkGame.LeaveSession();\r
+                            networkGame.SendChat(chatMessage);\r
+                            chatActive = false;\r
+                            break;\r
                         }\r
-                        currentState = lobbyState.Welcome;\r
-                \r
-                    }\r
-                    if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))\r
-                        networkGame.LocalGamer.IsReady = true;\r
+                        Keys[] k = currentKeyboardState.GetPressedKeys();\r
+                        Keys[] kp = previousKeyboardState.GetPressedKeys();\r
+                        List<Keys> newKeys = new List<Keys>();\r
 \r
-                    if (networkGame.HasActiveSession)\r
+                        for (int x = 0; x < k.Count(); x++) //copy new keys into array\r
+                        {\r
+                            if (!kp.Contains(k[x]))\r
+                            {\r
+                                newKeys.Add(k[x]);\r
+                            }\r
+                        }\r
+\r
+                        foreach(Keys ky in newKeys)\r
+                        {\r
+                            if(ky.Equals(Keys.Space))\r
+                                chatMessage = chatMessage + " ";\r
+                            else\r
+                                chatMessage = chatMessage + ky.ToString();\r
+                        }\r
+                        \r
+                    }\r
+                    else\r
                     {\r
-                        localPlayer = networkGame.LocalGamer;\r
-                        players = networkGame.NetworkGamers;\r
-                        if (players != null)\r
+                        updateChat(gameTime, networkGame);\r
+                        chatMessage = "";\r
+                        if (currentKeyboardState.IsKeyDown(Keys.T) && previousKeyboardState.IsKeyUp(Keys.T))\r
                         {\r
-                            allReady = true;\r
-                            foreach (NetworkGamer p in players)\r
-                                if (p.IsReady == false)\r
-                                {\r
-                                    allReady = false;\r
-                                    break;\r
-                                }\r
+                            chatActive = true;\r
+                        }\r
+                        if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                        {\r
+                            ready = false;\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
-                        //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 (networkGame.HasActiveSession)\r
                         {\r
-                            if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B))\r
+                            localPlayer = networkGame.LocalGamer;\r
+                            players = networkGame.NetworkGamers;\r
+                            if (players != null)\r
                             {\r
-                                networkGame.ForceStartGame();\r
+                                allReady = true;\r
+                                foreach (NetworkGamer p in players)\r
+                                    if (p.IsReady == false)\r
+                                    {\r
+                                        allReady = false;\r
+                                        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
                     }\r
-                    else\r
-                        currentState = lobbyState.Welcome;\r
-\r
                     break;\r
 \r
             }\r
@@ -371,7 +405,7 @@ namespace CS_3505_Project_06
 \r
                 case lobbyState.Connected:\r
                     DrawPlayerList(spriteBatch);\r
-                                        \r
+                    DrawChatInfo(spriteBatch);                    \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
@@ -399,6 +433,20 @@ namespace CS_3505_Project_06
             }\r
         }\r
 \r
+        private void DrawChatInfo(SpriteBatch spriteBatch)\r
+        {\r
+            if (currentChat.Count > 0)\r
+            {\r
+                for (int y = 0; y < currentChat.Count; y++)\r
+                {\r
+                    spriteBatch.DrawString(menuFont, currentChat.ElementAt(y).Sender + ": " + currentChat.ElementAt(y).Message\r
+                                            , new Vector2(400, 100 - y*10), Color.Blue, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+                }\r
+\r
+            }\r
+            if(chatActive)\r
+                spriteBatch.DrawString(menuFont, chatMessage, new Vector2(400, 100), Color.Green, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+        }\r
 \r
         private void DrawPlayerList(SpriteBatch spriteBatch)\r
         {\r
@@ -494,4 +542,4 @@ namespace CS_3505_Project_06
             }\r
         }\r
     }\r
-}\r
+}
\ No newline at end of file
This page took 0.031417 seconds and 4 git commands to generate.