Welcome,\r
CreateGame,\r
FindGame,\r
+ FindingGames, // TODO: New state.\r
+ JoiningGame, // TODO: New state.\r
Connected\r
}\r
\r
\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
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
{\r
currentState = lobbyState.Welcome;\r
ready = false;\r
- if (networkGame.sessionExists())\r
+ if (networkGame.HasActiveSession)\r
{\r
players = null;\r
networkGame.LeaveSession();\r
}\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.CreateSession(JoinedSession);\r
} \r
break;\r
\r
currentState = lobbyState.Welcome;\r
ready = false;\r
}\r
- availableSessions = networkGame.FindSessions();\r
- if (availableSessions != null)\r
- {\r
- networkGame.JoinSession(availableSessions[0]);\r
- currentState = lobbyState.Connected;\r
-\r
- availableSessions.Dispose();\r
- availableSessions = null;\r
- }\r
+ networkGame.FindSessions(FoundSessions);\r
+ currentState = lobbyState.FindingGames;\r
break;\r
\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
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
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
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
\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