From: brady Date: Wed, 31 Mar 2010 06:27:34 +0000 (+0000) Subject: Chat Started X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=a478c2016f3d96d03029a4010f9381f37028707a;p=chaz%2Fcarfire Chat Started git-svn-id: https://bd85.net/svn/cs3505_group@44 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- 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 c79b6a7..e580b04 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 @@ -61,6 +61,10 @@ namespace CS_3505_Project_06 int selectedSessionIndex; + bool chatActive; + String chatMessage; + Queue currentChat; + private enum lobbyState { Welcome, @@ -78,6 +82,9 @@ namespace CS_3505_Project_06 currentState = lobbyState.Welcome; selectedSessionIndex = 0; ready = false; + chatActive = false; + chatMessage = ""; + currentChat = new Queue(); } public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) @@ -148,21 +155,6 @@ namespace CS_3505_Project_06 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. @@ -172,6 +164,11 @@ namespace CS_3505_Project_06 Console.WriteLine("Exception as thrown during async call: " + exception.Message); } + private void UpdateChat(GameTime gameTime, NetworkGame networkGame) + { + currentChat.Concat(networkGame.ReceiveChats); + + } public long Update(GameTime gameTime, NetworkGame networkGame) { @@ -267,47 +264,84 @@ namespace CS_3505_Project_06 Console.WriteLine("Finding"); break; case lobbyState.Connected: - if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) + if (chatActive) { - ready = false; - if (networkGame.HasActiveSession) + if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) { - players = null; - networkGame.LeaveSession(); + networkGame.SendChat(chatMessage); + chatActive = false; + break; } - currentState = lobbyState.Welcome; - - } - if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) - networkGame.LocalGamer.IsReady = true; + Keys[] k = currentKeyboardState.GetPressedKeys(); + Keys[] kp = previousKeyboardState.GetPressedKeys(); + List newKeys = new List(); - if (networkGame.HasActiveSession) + for (int x = 0; x < k.Count(); x++) //copy new keys into array + { + if (!kp.Contains(k[x])) + { + newKeys.Add(k[x]); + } + } + + foreach(Keys ky in newKeys) + { + if(ky.Equals(Keys.Space)) + chatMessage = chatMessage + " "; + else + chatMessage = chatMessage + ky.ToString(); + } + + } + else { - localPlayer = networkGame.LocalGamer; - players = networkGame.NetworkGamers; - if (players != null) + updateChat(gameTime, networkGame); + chatMessage = ""; + if (currentKeyboardState.IsKeyDown(Keys.T) && previousKeyboardState.IsKeyUp(Keys.T)) { - allReady = true; - foreach (NetworkGamer p in players) - if (p.IsReady == false) - { - allReady = false; - break; - } + chatActive = true; + } + if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) + { + ready = false; + if (networkGame.HasActiveSession) + { + players = null; + networkGame.LeaveSession(); + } + currentState = lobbyState.Welcome; + } + if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) + networkGame.LocalGamer.IsReady = true; - //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 (networkGame.HasActiveSession) { - if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B)) + localPlayer = networkGame.LocalGamer; + players = networkGame.NetworkGamers; + if (players != null) { - networkGame.ForceStartGame(); + allReady = true; + foreach (NetworkGamer p in players) + if (p.IsReady == false) + { + allReady = false; + 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; } - else - currentState = lobbyState.Welcome; - break; } @@ -371,7 +405,7 @@ namespace CS_3505_Project_06 case lobbyState.Connected: DrawPlayerList(spriteBatch); - + DrawChatInfo(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) @@ -399,6 +433,20 @@ namespace CS_3505_Project_06 } } + private void DrawChatInfo(SpriteBatch spriteBatch) + { + if (currentChat.Count > 0) + { + for (int y = 0; y < currentChat.Count; y++) + { + spriteBatch.DrawString(menuFont, currentChat.ElementAt(y).Sender + ": " + currentChat.ElementAt(y).Message + , new Vector2(400, 100 - y*10), Color.Blue, 0f, zero, .6f, SpriteEffects.None, 1f); + } + + } + if(chatActive) + spriteBatch.DrawString(menuFont, chatMessage, new Vector2(400, 100), Color.Green, 0f, zero, .6f, SpriteEffects.None, 1f); + } private void DrawPlayerList(SpriteBatch spriteBatch) { @@ -494,4 +542,4 @@ namespace CS_3505_Project_06 } } } -} +} \ No newline at end of file