\r
int selectedSessionIndex;\r
\r
+ bool chatActive;\r
+ String chatMessage;\r
+ Queue<ChatInfo> currentChat;\r
+\r
private enum lobbyState\r
{\r
Welcome,\r
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
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
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
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
\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
}\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
}\r
}\r
}\r
-}\r
+}
\ No newline at end of file