X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=Project06%2FCS%203505%20Project%2006%2FCS%203505%20Project%2006%2FLobbyGUI.cs;h=17275a945adf4a946504354d09cd9f056ab52b05;hb=86fc3f310085b92db501df7dac8eb408919f5d72;hp=78ee37b7a9912c9dad0ebf700bf7b83be60d9dd7;hpb=87550d29aa4aa52e9c3e413e58877b494d7d7017;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 78ee37b..17275a9 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) { @@ -229,52 +226,122 @@ namespace CS_3505_Project_06 currentState = lobbyState.Welcome; ready = false; } + availableSessions = null; networkGame.ErrorDelegate = AsyncCallbackFailed; networkGame.FindSessions(FoundSessions); currentState = lobbyState.FindingGames; break; - case lobbyState.Connected: + case lobbyState.FindingGames: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) { + currentState = lobbyState.Welcome; ready = false; - if (networkGame.HasActiveSession) + } + if (availableSessions != null && availableSessions.Count == 0) + currentState = lobbyState.FindGame; + else if (availableSessions != null && availableSessions.Count > 0) + { + if (currentKeyboardState.IsKeyDown(Keys.D1) && previousKeyboardState.IsKeyUp(Keys.D1)) { - players = null; - networkGame.LeaveSession(); + networkGame.JoinSession(availableSessions[0], JoinedSession); + currentState = lobbyState.JoiningGame; + + availableSessions.Dispose(); + availableSessions = null; + } + if (currentKeyboardState.IsKeyDown(Keys.D2) && previousKeyboardState.IsKeyUp(Keys.D2)) + { + networkGame.JoinSession(availableSessions[0], JoinedSession); + currentState = lobbyState.JoiningGame; + + availableSessions.Dispose(); + availableSessions = null; } - currentState = lobbyState.Welcome; } - if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) - networkGame.LocalGamer.IsReady = true; - if (networkGame.HasActiveSession) + + Console.WriteLine("Finding"); + break; + case lobbyState.Connected: + if (chatActive) { - localPlayer = networkGame.LocalGamer; - players = networkGame.NetworkGamers; - if (players != null) + if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter)) { - allReady = true; - foreach (NetworkGamer p in players) - if (p.IsReady == false) - { - allReady = false; - break; - } + networkGame.SendChat(chatMessage); + chatActive = false; + break; } + Keys[] k = currentKeyboardState.GetPressedKeys(); + Keys[] kp = previousKeyboardState.GetPressedKeys(); + List newKeys = new List(); - //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]) + for (int x = 0; x < k.Count(); x++) //copy new keys into array { - if (currentKeyboardState.IsKeyDown(Keys.B) && previousKeyboardState.IsKeyUp(Keys.B)) + if (!kp.Contains(k[x])) { - networkGame.ForceStartGame(); + newKeys.Add(k[x]); } } + + foreach(Keys ky in newKeys) + { + if(ky.Equals(Keys.Space)) + chatMessage = chatMessage + " "; + else + chatMessage = chatMessage + ky.ToString(); + } + } else - currentState = lobbyState.Welcome; + { + UpdateChat(gameTime, networkGame); + chatMessage = ""; + if (currentKeyboardState.IsKeyDown(Keys.T) && previousKeyboardState.IsKeyUp(Keys.T)) + { + 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; + if (networkGame.HasActiveSession) + { + localPlayer = networkGame.LocalGamer; + players = networkGame.NetworkGamers; + if (players != null) + { + 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; + } break; } @@ -338,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) @@ -366,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) { @@ -461,4 +542,4 @@ namespace CS_3505_Project_06 } } } -} +} \ No newline at end of file