/* * Updates the lobby, detects key presses, called if we are in lobby */ void UpdateLobby() { KeyboardState keyState = Keyboard.GetState(); if (IsActive) { if (keyState.IsKeyDown(Keys.A)) { // Create a new session? CreateGame(); } else { if (keyState.IsKeyDown(Keys.R)) { games = null; } if (keyState.IsKeyDown(Keys.NumPad0) || keyState.IsKeyDown(Keys.D0)) { JoinGame(0); } if (keyState.IsKeyDown(Keys.NumPad1) || keyState.IsKeyDown(Keys.D1)) { JoinGame(1); } if (keyState.IsKeyDown(Keys.NumPad2) || keyState.IsKeyDown(Keys.D2)) { JoinGame(2); } if (keyState.IsKeyDown(Keys.NumPad3) || keyState.IsKeyDown(Keys.D3)) { JoinGame(3); } if (keyState.IsKeyDown(Keys.NumPad4) || keyState.IsKeyDown(Keys.D4)) { JoinGame(4); } if (keyState.IsKeyDown(Keys.NumPad5) || keyState.IsKeyDown(Keys.D5)) { JoinGame(5); } if (keyState.IsKeyDown(Keys.NumPad6) || keyState.IsKeyDown(Keys.D6)) { JoinGame(6); } if (keyState.IsKeyDown(Keys.NumPad7) || keyState.IsKeyDown(Keys.D7)) { JoinGame(7); } if (keyState.IsKeyDown(Keys.NumPad8) || keyState.IsKeyDown(Keys.D8)) { JoinGame(8); } if (keyState.IsKeyDown(Keys.NumPad9) || keyState.IsKeyDown(Keys.D9)) { JoinGame(9); } } } }
public bool joinSession() { currentState = CurrentState.Joining; try { using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(sessionType, Global.Constants.MAX_PLAYERS_LOCAL, sessionProperties)) { if (availableSessions.Count == 0) { throw new System.Exception(); } else { networkSession = NetworkSession.Join(availableSessions[0]); hookEvents(); } } } catch (Exception e) { currentState = CurrentState.JoinFailed; lastErrorMessage = e.Message; return(false); } currentState = CurrentState.Running; return(true); }
public static bool JoinSession() { SetStatus("Joining Session"); try { using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null)) { if (availableSessions.Count == 0) { SetStatus("No network sessions found."); return(false); } networkSession = NetworkSession.Join(availableSessions[0]); HookSessionEvents(); SetStatus("Connected!"); } return(true); } catch (Exception e) { Console.WriteLine(e.Message); SetStatus(e.Message); return(false); } }
/// <summary> /// Constructs a menu screen listing the available network sessions. /// </summary> public JoinSessionScreen(AvailableNetworkSessionCollection availableSessions) : base(Resources.JoinSession) { this.availableSessions = availableSessions; foreach (AvailableNetworkSession availableSession in availableSessions) { // Create menu entries for each available session. MenuEntry menuEntry = new AvailableSessionMenuEntry(availableSession); menuEntry.Selected += AvailableSessionMenuEntrySelected; MenuEntries.Add(menuEntry); // Matchmaking can return up to 25 available sessions at a time, but // we don't have room to fit that many on the screen. In a perfect // world we should make the menu scroll if there are too many, but it // is easier to just not bother displaying more than we have room for. if (MenuEntries.Count >= MaxSearchResults) break; } // Add the Back menu entry. MenuEntry backMenuEntry = new MenuEntry(Resources.Back); backMenuEntry.Selected += BackMenuEntrySelected; MenuEntries.Add(backMenuEntry); }
void JoinSession() { DrawMessage("Joining session..."); try { // Search for sessions. using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, maxLocalGamers, null)) { if (availableSessions.Count == 0) { errorMessage = "No network sessions found."; return; } // Join the first session we found. networkSession = NetworkSession.Join(availableSessions[0]); HookSessionEvents(); } } catch (Exception e) { errorMessage = e.Message; } }
/// <summary> /// Constructs a menu screen listing the available network sessions. /// </summary> public JoinSessionScreen(AvailableNetworkSessionCollection availableSessions) : base("") { this.availableSessions = availableSessions; foreach (AvailableNetworkSession availableSession in availableSessions) { // Create menu entries for each available session. MenuEntry menuEntry = new AvailableSessionMenuEntry(availableSession); menuEntry.Selected += AvailableSessionMenuEntrySelected; MenuEntries.Add(menuEntry); // Matchmaking can return up to 25 available sessions at a time, but // we don't have room to fit that many on the screen. In a perfect // world we should make the menu scroll if there are too many, but it // is easier to just not bother displaying more than we have room for. if (MenuEntries.Count >= MaxSearchResults) { break; } } // Add the Back menu entry. MenuEntry backMenuEntry = new MenuEntry("Back"); backMenuEntry.Selected += BackMenuEntrySelected; MenuEntries.Add(backMenuEntry); }
/* * Draws the lobby screen */ void DrawLobby() { string message = "A = Host Game\n" + "\nGames( 'r' to refresh )"; string players = "Players\n"; if (Gamer.SignedInGamers.Count != 0 && games == null) { // Search for Games games = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); } if (games != null) { for (int i = 0; i < games.Count(); i++) { message += "\n" + i + ") " + games[i].HostGamertag + "'s Game"; players += games[i].CurrentGamerCount.ToString() + "\n"; } } spriteBatch.Begin(); spriteBatch.Draw(background_lobby, mainFrame, Color.White); spriteBatch.DrawString(lobbyFont, players, new Vector2(500, 270), Color.Black); spriteBatch.DrawString(lobbyFont, "Lobby", new Vector2(100, 250), Color.Black); spriteBatch.DrawString(lobbyFont, message, new Vector2(100, 270), Color.Black); spriteBatch.End(); }
public virtual void FindSession() { // Search for sessions. using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, maximumLocalPlayers, null)) { if (availableSessions.Count == 0) { sayMessage("No network sessions found."); return; } else { sayMessage("Found an available session at host " + availableSessions[0].HostGamertag); Session = NetworkSession.Join(availableSessions[0]); } } if (OnJoin != null) { OnJoin(); } }
public void SearchForGame() { if (Gamer.SignedInGamers.Count == 0) { SignIn(); } else { if (_session != null) { _session.Dispose(); } AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); if (sessions.Count > 0) { try { AvailableNetworkSession mySession = sessions[0]; _session = NetworkSession.Join(mySession); _session.GamerLeft += new EventHandler <GamerLeftEventArgs>(Client_GamerLeft); GameMain.ChangeState(GameState.PlayingClient); IsHost = false; } catch (Exception ex) { // Not the best solution, but... GameMain.ChangeState(GameState.TitleScreen); } } } }
/// <summary> /// Event handler for when the asynchronous find network sessions /// operation has completed. /// </summary> void FindSessionsOperationCompleted(object sender, OperationCompletedEventArgs e) { try { // End the asynchronous find network sessions operation. AvailableNetworkSessionCollection availableSessions = Microsoft.Xna.Framework.Net.NetworkSession.EndFind(e.AsyncResult); if (availableSessions.Count == 0) { // If we didn't find any sessions, display an error. availableSessions.Dispose(); ScreenManager.AddScreen( new MessageBoxScreen(Resources.NoSessionsFound, false)); } else { // If we did find some sessions, proceed to the JoinSessionScreen. ScreenManager.AddScreen(new JoinSessionScreen(availableSessions)); } } catch (NetworkException exception) { ScreenManager.AddScreen(new NetworkErrorScreen(exception)); } catch (GamerPrivilegeException exception) { ScreenManager.AddScreen(new NetworkErrorScreen(exception)); } }
/// <summary> /// Event handler for when the asynchronous find network sessions /// operation has completed. /// </summary> void FindSessionsOperationCompleted(object sender, OperationCompletedEventArgs e) { GameScreen nextScreen; try { // End the asynchronous find network sessions operation. AvailableNetworkSessionCollection availableSessions = NetworkSession.EndFind(e.AsyncResult); if (availableSessions.Count == 0) { // If we didn't find any sessions, display an error. availableSessions.Dispose(); nextScreen = new MessageBoxScreen(Resources.NoSessionsFound, false); } else { // If we did find some sessions, proceed to the JoinSessionScreen. nextScreen = new JoinSessionScreen(availableSessions); } } catch (Exception exception) { nextScreen = new NetworkErrorScreen(exception); } ScreenManager.AddScreen(nextScreen, ControllingPlayer); }
void joinSession_Pressed(object sender, EventArgs e) { if (!Guide.IsVisible && !allScreens["chatScreen"].Visible) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, 2, null); allScreens["listSessions"].Visible = true; allScreens["titleScreen"].Visible = false; allScreens["listSessions"].AdditionalSprites.RemoveAll(ts => !(ts is TextSprite) || ts.Cast <TextSprite>().HoverColor != Color.LimeGreen); float y = 50; float x = 100; for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++) { AvailableNetworkSession availableSession = availableSessions[sessionIndex]; string HostGamerTag = availableSession.HostGamertag; int GamersInSession = availableSession.CurrentGamerCount; SessionInfoDisplay info = new SessionInfoDisplay(spriteBatch, new Vector2(x, y), font, HostGamerTag + ": " + GamersInSession + "/2 gamers", availableSession); info.IsHoverable = true; info.NonHoverColor = Color.Black; info.HoverColor = Color.White; info.Pressed += new EventHandler(info_Pressed); allScreens["listSessions"].AdditionalSprites.Add(info); } } }
public SearchLocalNetworkScreen(PlayerIndex playerIndex, AvailableNetworkSessionCollection availableSessions) : base("Local Network Game Search") { currentPlayer = playerIndex; IsPopupWindow = true; this.availableSessions = availableSessions; if (availableSessions.Count == 0) { Games = new MenuEntry("No Games found"); returnEntry = new MenuEntry("Return"); MenuEntries.Add(Games); } else { gameCount = 0; totalGames = availableSessions.Count; currentSessionSelected = availableSessions[0]; Games = new MenuEntry("Game: 0 / " + gameCount); gameMode = new MenuEntry("Game mode: " + GameType()); highScore = new MenuEntry("Hi score: " + WinningScore()); joinGame = new MenuEntry("Join this game"); joinGame.Selected += JoinSession; MenuEntries.Add(Games); MenuEntries.Add(gameMode); MenuEntries.Add(highScore); MenuEntries.Add(joinGame); } // hook up event handlers returnEntry.Selected += GoBack; MenuEntries.Add(returnEntry); }
private static void FindSessionsComplete(IAsyncResult result) { AvailableNetworkSessionCollection sessions = NetworkSession.EndFind(result); FindSessionCompleteHandler call = (FindSessionCompleteHandler)result.AsyncState; call.Invoke(sessions); }
/// <summary> /// Callback to receive the network-session search results from quick-match. /// </summary> void QuickMatchSearchCompleted(object sender, OperationCompletedEventArgs e) { try { AvailableNetworkSessionCollection availableSessions = NetworkSession.EndFind(e.AsyncResult); if ((availableSessions != null) && (availableSessions.Count > 0)) { // join the session try { IAsyncResult asyncResult = NetworkSession.BeginJoin( availableSessions[0], null, null); // create the busy screen NetworkBusyScreen busyScreen = new NetworkBusyScreen( "Joining the session...", asyncResult); busyScreen.OperationCompleted += QuickMatchSessionJoined; ScreenManager.AddScreen(busyScreen); } catch (NetworkException ne) { const string message = "Failed joining the session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine("Failed to join session: " + ne.Message); } catch (GamerPrivilegeException gpe) { const string message = "You do not have permission to join a session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine( "Insufficient privilege to join session: " + gpe.Message); } } else { const string message = "No matches were found."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); } } catch (GamerPrivilegeException gpe) { MessageBoxScreen messageBox = new MessageBoxScreen(gpe.Message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); } }
/// <summary> /// This event handler takes the background worker's work /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void findAvailableSessions(object sender, EventArgs e) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, // Session Type 4, // Max local gamers null // Search Properties ); }
/// <summary> /// Raised when a Live find query returns /// </summary> /// <param name="asyncResult"></param> private void OnLiveSessionsFound(IAsyncResult asyncResult) { var sessions = new List <AvailableSession>(); AvailableNetworkSessionCollection availableLiveSessions = NetworkSession.EndFind(asyncResult); foreach (AvailableNetworkSession availableLiveSession in availableLiveSessions) { sessions.Add(new LiveAvailableSession(availableLiveSession)); } OnSessionsFound(sessions.AsReadOnly()); }
public static AvailableNetworkSession Session() { List <SignedInGamer> list = new List <SignedInGamer>(1); list.Add(UI.main.signedInGamer); AvailableNetworkSessionCollection availableNetworkSessionCollection = NetworkSession.Find(NetworkSessionType.PlayerMatch, list, session.joinableSession.SessionProperties); session = null; if (availableNetworkSessionCollection.Count <= 0) { return(null); } return(availableNetworkSessionCollection[0]); }
public void joinSession() { using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null)) { if (availableSessions.Count == 0) { networkState = "No network sessions were found."; } else { network = NetworkSession.Join(availableSessions[0]); } } }
/* Completion of looking for sessions. */ protected virtual void OnSessionsFound(IAsyncResult ar) { findAsync_ = null; AvailableNetworkSessionCollection availableSessions = NetworkSession.EndFind(ar); if (availableSessions.Count != 0) { /* Pick one of the available sessions. */ List <AvailableNetworkSession> toChooseFrom = new List <AvailableNetworkSession>(); Trace.WriteLine(String.Format("Found {0} potential network sessions.", availableSessions.Count)); foreach (AvailableNetworkSession ans in availableSessions) { if (ans.OpenPublicGamerSlots < saveLocalPlayerCount && ans.OpenPublicGamerSlots < SignedInGamer.SignedInGamers.Count) { // full continue; } if (sessionType != SessionType.HighscoresOnly || !previousSessionHosts.Member(ans.HostGamertag)) { // this seems like an OK session, use that! toChooseFrom.Add(ans); } } if (toChooseFrom.Count > 0) { // pick one at random AvailableNetworkSession ans = toChooseFrom[rand.Next(toChooseFrom.Count)]; previousSessionHosts.Add(ans.HostGamertag); Trace.WriteLine(String.Format("Connecting to session hosted by '{0}'", ans.HostGamertag)); ConnectToSession(ans); return; } else { /* I went through all the possible sessions, so now I can re-start looking * at hosts I've previously talked to. */ previousSessionHosts.Clear(); } } // OK, nothing matched -- try to create something for others to find Trace.WriteLine("Creating session because no available session was suitable."); Debug.Assert(createAsync_ == null); createAsync_ = NetworkSession.BeginCreate(netType, saveLocalPlayerCount, saveTotalPlayerCount, 0, saveProps, OnSessionCreated, null); Debug.Assert(createAsync_.CompletedSynchronously == false); }
public static void FindSessionsThread() { NetworkSessionProperties networkSessionProperties = new NetworkSessionProperties(); UI main = UI.main; if (main.HasOnline()) { SignedInGamer signedInGamer = main.signedInGamer; if (signedInGamer != null) { try { List <SignedInGamer> list = new List <SignedInGamer>(1); list.Add(signedInGamer); FriendCollection friends = signedInGamer.GetFriends(); int num = friends.Count - 1; while (num >= 0 && !stopSessionFinderThread) { FriendGamer friendGamer = friends[num]; if (friendGamer.IsJoinable) { ulong xuid = friendGamer.GetXuid(); networkSessionProperties[0] = (int)xuid; networkSessionProperties[1] = (int)(xuid >> 32); AvailableNetworkSessionCollection availableNetworkSessionCollection = NetworkSession.Find(NetworkSessionType.PlayerMatch, list, networkSessionProperties); if (availableNetworkSessionCollection.Count > 0) { lock (availableSessions) { availableSessions.Add(new JoinableSession(availableNetworkSessionCollection[0])); } } if (stopSessionFinderThread) { break; } Thread.Sleep(5000); } num--; } } catch (Exception) { } } } stopSessionFinderThread = false; sessionFinderThread = null; }
/// <summary> /// Callback to receive the network-session search results. /// </summary> internal void SessionsFound(object sender, OperationCompletedEventArgs e) { try { availableSessions = NetworkSession.EndFind(e.AsyncResult); } catch (NetworkException ne) { const string message = "Failed searching for the session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine("Failed to search for session: " + ne.Message); } catch (GamerPrivilegeException gpe) { const string message = "You do not have permission to search for a session. "; MessageBoxScreen messageBox = new MessageBoxScreen(message + gpe.Message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine( "Insufficient privilege to search for session: " + gpe.Message); } MenuEntries.Clear(); if (availableSessions != null) { foreach (AvailableNetworkSession availableSession in availableSessions) { if (availableSession.CurrentGamerCount < World.MaximumPlayers) { MenuEntries.Add(availableSession.HostGamertag + " (" + availableSession.CurrentGamerCount.ToString() + "/" + World.MaximumPlayers.ToString() + ")"); } if (MenuEntries.Count >= maximumSessions) { break; } } } }
protected void Update_FindSession() { //Sessions is a list of AvailableNetworkSessions(I think lol), basically storing AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); if (sessions.Count == 0) { currentGameState = GameState.CreateSession; } else { //basically, NetworkSession.Join method takes a AvailableNetworkSession networkSession = NetworkSession.Join(sessions[0]); WireUpEvents(); currentGameState = GameState.Start; } }
public JoinSessionScreen(AvailableNetworkSessionCollection availableSessions) : base("Join Game") { _availableSessions = availableSessions; foreach (AvailableNetworkSession availableSession in _availableSessions) { MenuEntry menuEntry = new AvailableSessionMenuEntry(availableSession); menuEntry.Selected += AvaibleSessionMenuEntrySelected; MenuEntries.Add(menuEntry); if (MenuEntries.Count >= _maxSearchResults) break; } MenuEntry backMenuEntry = new MenuEntry("Back"); backMenuEntry.Selected += BackMenuEntrySelected; MenuEntries.Add(backMenuEntry); }
public void doSessionSearch() { if (_availableSessions == null) { if (_netSession != null) { _netSession.Dispose(); _netSession = null; } _availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); } if (_availableSessions != null) { foreach (AvailableNetworkSession session in _availableSessions) { _sessionList.Add(session); } } }
void JoinGameHandler(object sender, EventArgs e) { AvailableNetworkSessionCollection sessions = NetworkSession.Find(NetworkSessionType.SystemLink, 2, null); if (sessions.Count < 1) { return; } Session = NetworkSession.Join(sessions[0]); if (Session != null) { HookSessionEvents(); UnhookHomeStateEvents(); GlobalState = new LobbyState(); GlobalState.Initialize(null); GlobalState.LoadContent(Content); HookLobbyStateEvents(); } }
public void JoinSession() { try { using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find(networkSessionType, maxLocalGamers, null)) { if (availableSessions.Count == 0) { errorMessage = "No network sessions found."; } else { networkSession = NetworkSession.Join(availableSessions[0]); HookSessionEvents(); } } } catch (Exception e) { errorMessage = e.Message; } }
public void Dispose() { if (_netSession.IsHost) { _netSession.EndGame(); } _netSession.Dispose(); _netSession = null; _availableSessions = null; _hasLeft = true; _remoteMapName = ""; _packetReader.BaseStream.Flush(); _packetWriter.BaseStream.Flush(); _remoteItemList = null; _remoteMatch = null; _remoteMatchType = 999; _sender = null; _sessionList.Clear(); _isHost = false; _isClient = false; _failure = false; }
private void EndAsynchSearch(IAsyncResult result) { AvailableNetworkSessionCollection activeSessions = NetworkSession.EndFind(result); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); currentGameState = GameState.InSession; } }
/// <summary> /// Helper method for joining a hosted network session /// </summary> private void JoinSession() { try { using (AvailableNetworkSessionCollection availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, // Session Type 4, // Max local gamers null // Search Properties )) { if (availableSessions.Count == 0) { // No sessions available // TODO: Offer feedback return; } // Join the first session found session = NetworkSession.Join(availableSessions[0]); // Set ourselves as guest isHost = false; // Set up the session event handlers HookSessonEvents(); // Update our game state game.GameState = GameState.Gameplay; } } catch (Exception e) { // TODO: Report Errors } }
//Handle menu screen input and update. public void executeGameLogic(GameTime gameTime) { KeyboardState newKeyState = Keyboard.GetState(); if(currentMenu == mainmenu) { //don't handle input if the LIVE overlay is active if (Guide.IsVisible) { return; } if (newKeyState.IsKeyDown(Keys.N) && !oldKeyState.IsKeyDown(Keys.N))//New Session. { currentMenu = createdlobby; if (NetworkObject.Instance().getNetworked()) { if (!NetworkObject.Instance().CreateSession()) currentMenu = mainmenu; } } else if (newKeyState.IsKeyDown(Keys.J) && !oldKeyState.IsKeyDown(Keys.J))//Join Session. { if (NetworkObject.Instance().getNetworked()) { currentMenu = searchLobbies; int maxLocalPlayers = 1; availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, maxLocalPlayers, null); selectedSessionIndex = 0; } } else if (newKeyState.IsKeyDown(Keys.Q) && !oldKeyState.IsKeyDown(Keys.Q))//Quit game. { Environment.Exit(0); } } else if (currentMenu == createdlobby) { ReceiveNetworkData(); if (newKeyState.IsKeyDown(Keys.B) && !oldKeyState.IsKeyDown(Keys.B))//Back to Main menu. { currentMenu = mainmenu; if (NetworkObject.Instance().getNetworked()) { NetworkObject.Instance().disposeNetworkSession(); cleanAvailableSessions(); } } else if (newKeyState.IsKeyDown(Keys.S) && !oldKeyState.IsKeyDown(Keys.S))//Start the game? { if (NetworkObject.Instance().getNetworked()) { if (NetworkObject.Instance().getNetworksession().IsEveryoneReady) { NetworkObject.Instance().getNetworksession().StartGame(); active = false; } } else { active = false; } } else if (newKeyState.IsKeyDown(Keys.R) && !oldKeyState.IsKeyDown(Keys.R))//Indicate ready. { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady && (gamer.Tag as Human).GetPickedTeam()) gamer.IsReady = true; else gamer.IsReady = false; } } } else if (newKeyState.IsKeyDown(Keys.E) && !oldKeyState.IsKeyDown(Keys.E)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) (gamer.Tag as Human).SetTeam(1); } } } else if (newKeyState.IsKeyDown(Keys.L) && !oldKeyState.IsKeyDown(Keys.L)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) (gamer.Tag as Human).SetTeam(2); } } } else if (newKeyState.IsKeyDown(Keys.Left) && !oldKeyState.IsKeyDown(Keys.Left)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) { if (selectedShipIndex > 0) { selectedShipIndex--; (gamer.Tag as Human).SetSelectedShip(GameObject.Instance().GetShipCollection().ElementAt(selectedShipIndex).Key); } } } } } else if (newKeyState.IsKeyDown(Keys.Right) && !oldKeyState.IsKeyDown(Keys.Right)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) { if (selectedShipIndex < GameObject.Instance().GetShipCollection().Count - 1) //max { selectedShipIndex++; (gamer.Tag as Human).SetSelectedShip(GameObject.Instance().GetShipCollection().ElementAt(selectedShipIndex).Key); } } } } } SendNetworkData(); } else if (currentMenu == joinedlobby) { ReceiveNetworkData(); if (newKeyState.IsKeyDown(Keys.B) && !oldKeyState.IsKeyDown(Keys.B))//Back to Main menu. { currentMenu = mainmenu; cleanAvailableSessions(); NetworkObject.Instance().disposeNetworkSession(); } else if (newKeyState.IsKeyDown(Keys.R) && !oldKeyState.IsKeyDown(Keys.R))//Indicate ready. { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady && (gamer.Tag as Human).GetPickedTeam()) gamer.IsReady = true; else gamer.IsReady = false; } } } else if (newKeyState.IsKeyDown(Keys.E) && !oldKeyState.IsKeyDown(Keys.E)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if(!gamer.IsReady) (gamer.Tag as Human).SetTeam(1); } } } else if (newKeyState.IsKeyDown(Keys.L) && !oldKeyState.IsKeyDown(Keys.L)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) (gamer.Tag as Human).SetTeam(2); } } } else if (newKeyState.IsKeyDown(Keys.Left) && !oldKeyState.IsKeyDown(Keys.Left)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) { if (selectedShipIndex > 0) { selectedShipIndex--; (gamer.Tag as Human).SetSelectedShip(GameObject.Instance().GetShipCollection().ElementAt(selectedShipIndex).Key); } } } } } else if (newKeyState.IsKeyDown(Keys.Right) && !oldKeyState.IsKeyDown(Keys.Right)) { if (NetworkObject.Instance().getNetworked()) { foreach (LocalNetworkGamer gamer in NetworkObject.Instance().getNetworksession().LocalGamers) { if (!gamer.IsReady) { if (selectedShipIndex < GameObject.Instance().GetShipCollection().Count - 1) //max { selectedShipIndex++; (gamer.Tag as Human).SetSelectedShip(GameObject.Instance().GetShipCollection().ElementAt(selectedShipIndex).Key); } } } } } SendNetworkData(); } else if (currentMenu == searchLobbies) { if (newKeyState.IsKeyDown(Keys.B) && !oldKeyState.IsKeyDown(Keys.B))//Back to Main menu. { currentMenu = mainmenu; } else if (newKeyState.IsKeyDown(Keys.Up) && !oldKeyState.IsKeyDown(Keys.Up)) { if (selectedSessionIndex > 0) selectedSessionIndex--; } else if (newKeyState.IsKeyDown(Keys.Down) && !oldKeyState.IsKeyDown(Keys.Down)) { if (selectedSessionIndex < availableSessions.Count) selectedSessionIndex++; } else if (newKeyState.IsKeyDown(Keys.J) && !oldKeyState.IsKeyDown(Keys.J))//Join lobby. { if (availableSessions.Count > 0) { currentMenu = joinedlobby; NetworkSession networkSession = NetworkSession.Join(availableSessions[selectedSessionIndex]); NetworkObject.Instance().setNetworkSession(networkSession); cleanAvailableSessions(); } } } else if (currentMenu == victoryLobby) { if (newKeyState.IsKeyDown(Keys.B) && !oldKeyState.IsKeyDown(Keys.B))//Back to Main menu. { foreach (SignedInGamer loc in SignedInGamer.SignedInGamers) { loc.Tag = new Human(loc.Gamertag); } currentMenu = mainmenu; NetworkObject.Instance().disposeNetworkSession(); } } oldKeyState = newKeyState; if (NetworkObject.Instance().getNetworked() && NetworkObject.Instance().getNetworksession() != null) { NetworkObject.Instance().getNetworksession().Update(); } }
protected void HandleLobbyInput() { KeyboardState keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.A)) { foreach (LocalNetworkGamer gamer in networkSession.LocalGamers) gamer.IsReady = true; } if (keystate.IsKeyDown(Keys.B)) { networkSession.Dispose(); networkSession = null; availableSessions = null; SetMainMenuOptions(); } // The host checks if everyone is ready, and moves // to game play if true. if (networkSession != null) { if (networkSession.IsHost) { if (networkSession.IsEveryoneReady) networkSession.StartGame(); } } // Pump the underlying session object. //if (networkSession != null) networkSession.Update(); }
protected override void Update(GameTime gameTime) { GamePadState padState = GamePad.GetState(PlayerIndex.One); if (padState.Buttons.Back == ButtonState.Pressed) { this.Exit(); } KeyboardState keybState = Keyboard.GetState(); if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.SearchSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to SearchSession"); } } break; case GameState.SearchSession: { NetworkSessionProperties findProperties = new NetworkSessionProperties(); findProperties[0] = 3; findProperties[1] = 4096; AvailableNetworkSessionCollection activeSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 4, findProperties); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); command = "[Press X to signal you're ready]"; currentGameState = GameState.InSession; } } break; case GameState.CreateSession: { NetworkSessionProperties createProperties = new NetworkSessionProperties(); createProperties[0] = 3; createProperties[1] = 4096; networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 16, 0, createProperties); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); command = "[Press X to signal you're ready]"; currentGameState = GameState.InSession; } break; case GameState.InSession: { switch (networkSession.SessionState) { case NetworkSessionState.Lobby: { if ((keybState != lastKeybState) || (padState != lastPadState)) { if (keybState.IsKeyDown(Keys.X) || (padState.IsButtonDown(Buttons.X))) { LocalNetworkGamer localGamer = networkSession.LocalGamers[0]; localGamer.IsReady = !localGamer.IsReady; } } if (networkSession.IsHost) { if (networkSession.AllGamers.Count > 1) { if (networkSession.IsEveryoneReady) { networkSession.StartGame(); log.Add("All players ready -- start the game!"); } } } } break; case NetworkSessionState.Playing: { if (networkSession.IsHost) { if ((keybState != lastKeybState) || (padState != lastPadState)) { if (keybState.IsKeyDown(Keys.Y) || (padState.IsButtonDown(Buttons.Y))) { networkSession.EndGame(); } } } } break; } networkSession.Update(); } break; } } lastKeybState = keybState; base.Update(gameTime); }
protected void HandleTitleScreenInput() { KeyboardState keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.A)) { CreateSession(); } else if (keystate.IsKeyDown(Keys.X)) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, 2, null); selectedSessionIndex = 0; } else if (keystate.IsKeyDown(Keys.B)) { SetMainMenuOptions(); } }
public void CheckNetworkSearch() { if (IsCreating || IsJoining || IsSearching) { bool TemparyProfiles = false; foreach (CompletePlayer player in game.ThisGamesPlayers) { if (player.InUse && !player.IsProfile) { TemparyProfiles = true; } } if (!TemparyProfiles) //if(true) { if (IsSearching && FindResult.IsCompleted) { FindResult.AsyncWaitHandle.WaitOne(); try { availableSessions = NetworkSession.EndFind(FindResult); if (availableSessions.Count == 0) { SetString("No Games Found, Creating Game..."); CreateGame(); } else { SetString(availableSessions.Count.ToString() + " Games Found\nFinding Best Game"); SortSessions(); } IsSearching = false; } catch (Exception e) { // if(networkSession==null) if (e.Message != null) { OnlineString = " "; game.ErrorMessage = e.Message.Replace(". ", ".\n"); game.menus.GoTo("Error", false); IsCreating = false; IsJoining = false; IsSearching = false; } } IsSearching = false; } if (IsJoining && JoinResult.IsCompleted) { JoinResult.AsyncWaitHandle.WaitOne(); try { networkSession = NetworkSession.EndJoin(JoinResult); HookSessionEvents(); BeginOnlineGameAsGuest(); } catch (Exception e) { // if (networkSession == null) if (e.Message != null) { OnlineString = " "; game.ErrorMessage = e.Message.Replace(". ", ".\n"); game.menus.GoTo("Error", false); IsCreating = false; IsJoining = false; IsSearching = false; } } IsJoining = false; } if (IsCreating && CreateResult.IsCompleted) { CreateResult.AsyncWaitHandle.WaitOne(); try { networkSession = NetworkSession.EndCreate(CreateResult); HookSessionEvents(); BeginOnlineGameAsHost(); } catch (Exception e) { if (e.Message != null) { OnlineString = " "; game.ErrorMessage = e.Message.Replace(". ", ".\n"); game.menus.GoTo("Error", false); IsCreating = false; IsJoining = false; IsSearching = false; } } IsCreating = false; } } else { OnlineString = " "; game.ErrorMessage = "No Temporary Profiles May Be Taken Online \n Sign into XBOX LIVE Guest Profiles Instead"; game.menus.GoTo("Error", false); IsCreating = false; IsJoining = false; IsSearching = false; } } }
/// <summary> /// This event handler takes the background worker's work /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void findAvailableSessions(object sender, EventArgs e) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, // Session Type 4, // Max local gamers null // Search Properties ); }
private void UpdateSessions() { menu.RemoveAll(); availableSessions = NetworkManager.GetInstance().GetAvailableSessions(); AvailableNetworkSession availableSession; for (int i = 0; i < availableSessions.Count; ++i) { availableSession = availableSessions[i]; string HostGamerTag = availableSession.HostGamertag; int GamersInSession = availableSession.CurrentGamerCount; int OpenPrivateGamerSlots = availableSession.OpenPrivateGamerSlots; int OpenPublicGamerSlots = availableSession.OpenPublicGamerSlots; string sessionInformation = HostGamerTag + "("+ GamersInSession + "/" + OpenPrivateGamerSlots + "/" + OpenPublicGamerSlots + ")"; menu.AddComponent(new TextComponent(100, 100 * (i+1), sessionInformation, "KartsFont")); } }
public AvailableNetworkSessionCollection GetAvailableSessions() { /*if (availableSessions == null) { availableSessions = FindSessions(); } */ availableSessions = FindSessions(); return availableSessions; }
public AvailableNetworkSessionCollection FindSessions() { availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, MAX_LOCAL_PLAYERS, null); return availableSessions; }
protected void HandleTitleScreenInput() { if (currentKeyboardState.IsKeyDown(Keys.A)) { CreateSession(); } else if (currentKeyboardState.IsKeyDown(Keys.X)) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, 1, null); selectedSessionIndex = 0; } else if (currentKeyboardState.IsKeyDown(Keys.B)) { Exit(); } }
public static void endFind(IAsyncResult result) { availableSessions = NetworkSession.EndFind(result); if (availableSessions.Count > 0) { foreach (var session in availableSessions) { Console.WriteLine("Game by: " + session.HostGamertag + " found."); NetworkSession.BeginJoin(session, endJoin, session); } } else { Console.WriteLine("No games found, creating a new one."); session = NetworkSession.Create(NetworkSessionType.PlayerMatch, 1, 4); session.AllowHostMigration = true; session.AllowJoinInProgress = true; session.GamerJoined += gamerJoinedHandler; session.GamerLeft += gamerLeftHandler; session.GameStarted += gameStartedHandler; session.GameEnded += gameEndedHandler; session.SessionEnded += networkSessionEndedHandler; } }
//Find network Sessions void FindSession() { availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); selectedSessionIndex = 0; }
public static AvailableNetworkSessionCollection EndFind (IAsyncResult result) { AvailableNetworkSessionCollection returnValue = null; List<AvailableNetworkSession> networkSessions = new List<AvailableNetworkSession>(); try { // Retrieve the delegate. #if WINDOWS_PHONE MonoGamerPeer.FindResults(networkSessions); #else AsyncResult asyncResult = (AsyncResult)result; // Wait for the WaitHandle to become signaled. result.AsyncWaitHandle.WaitOne (); // Call EndInvoke to retrieve the results. if (asyncResult.AsyncDelegate is NetworkSessionAsynchronousFind) { returnValue = ((NetworkSessionAsynchronousFind)asyncResult.AsyncDelegate).EndInvoke (result); MonoGamerPeer.FindResults(networkSessions); } #endif } finally { // Close the wait handle. result.AsyncWaitHandle.Close (); } returnValue = new AvailableNetworkSessionCollection(networkSessions); return returnValue; }
private void cleanAvailableSessions() { if (availableSessions != null) { availableSessions.Dispose(); availableSessions = null; } }
protected void HandleAvailableSessionsInput() { KeyboardState keystate = Keyboard.GetState(); if (keystate.IsKeyDown(Keys.A)) { // Join the selected session. if (availableSessions.Count > 0) { networkSession = NetworkSession.Join( availableSessions[selectedSessionIndex]); HookSessionEvents(); availableSessions.Dispose(); availableSessions = null; } } else if (keystate.IsKeyDown(Keys.Up)) { // Select the previous session from the list. if (selectedSessionIndex > 0) selectedSessionIndex--; } else if (keystate.IsKeyDown(Keys.Down)) { // Select the next session from the list. if (selectedSessionIndex < availableSessions.Count - 1) selectedSessionIndex++; } else if (keystate.IsKeyDown(Keys.B)) { // Go back to the title screen. availableSessions.Dispose(); availableSessions = null; SetMainMenuOptions(); } }
/// <summary> /// Callback to receive the network-session search results. /// </summary> internal void SessionsFound(object sender, OperationCompletedEventArgs e) { try { availableSessions = NetworkSession.EndFind(e.AsyncResult); } catch (NetworkException ne) { const string message = "Failed searching for the session."; MessageBoxScreen messageBox = new MessageBoxScreen(message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine("Failed to search for session: " + ne.Message); } catch (GamerPrivilegeException gpe) { const string message = "You do not have permission to search for a session. "; MessageBoxScreen messageBox = new MessageBoxScreen(message + gpe.Message); messageBox.Accepted += FailedMessageBox; messageBox.Cancelled += FailedMessageBox; ScreenManager.AddScreen(messageBox); System.Console.WriteLine( "Insufficient privilege to search for session: " + gpe.Message); } MenuEntries.Clear(); if (availableSessions != null) { foreach (AvailableNetworkSession availableSession in availableSessions) { if (availableSession.CurrentGamerCount < World.MaximumPlayers) { MenuEntries.Add(availableSession.HostGamertag + " (" + availableSession.CurrentGamerCount.ToString() + "/" + World.MaximumPlayers.ToString() + ")"); } if (MenuEntries.Count >= maximumSessions) { break; } } } }
void joinSession_Pressed(object sender, EventArgs e) { if (!Guide.IsVisible && !allScreens["chatScreen"].Visible) { availableSessions = NetworkSession.Find( NetworkSessionType.SystemLink, 2, null); allScreens["listSessions"].Visible = true; allScreens["titleScreen"].Visible = false; allScreens["listSessions"].AdditionalSprites.RemoveAll(ts => !(ts is TextSprite) || ts.Cast<TextSprite>().HoverColor != Color.LimeGreen); float y = 50; float x = 100; for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++) { AvailableNetworkSession availableSession = availableSessions[sessionIndex]; string HostGamerTag = availableSession.HostGamertag; int GamersInSession = availableSession.CurrentGamerCount; SessionInfoDisplay info = new SessionInfoDisplay(spriteBatch, new Vector2(x, y), font, HostGamerTag + ": " + GamersInSession + "/2 gamers", availableSession); info.IsHoverable = true; info.NonHoverColor = Color.Black; info.HoverColor = Color.White; info.Pressed += new EventHandler(info_Pressed); allScreens["listSessions"].AdditionalSprites.Add(info); } } }
private void FindAvailableSessions() { DrawMessage("Looking For Sessions..."); try { // Search for sessions. using (availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, maxLocalGamers, null)) { if (availableSessions.Count == 0) { errorMessage = "No network sessions found."; return; } //availableSessions = sessionsFound; looked = true; HookSessionEvents(); } } catch (Exception e) { errorMessage = e.Message; } }
/* * Draws the lobby screen */ void DrawLobby() { string message = "A = Host Game\n" + "\nGames( 'r' to refresh )"; string players = "Players\n"; if (Gamer.SignedInGamers.Count != 0 && games == null) { // Search for Games games = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); } if (games != null) { for (int i = 0; i < games.Count(); i++) { message += "\n" + i + ") " + games[i].HostGamertag + "'s Game"; players += games[i].CurrentGamerCount.ToString() + "\n"; } } spriteBatch.Begin(); spriteBatch.Draw(background_lobby, mainFrame, Color.White); spriteBatch.DrawString(lobbyFont, players, new Vector2(500, 270), Color.Black); spriteBatch.DrawString(lobbyFont, "Lobby", new Vector2(100, 250), Color.Black); spriteBatch.DrawString(lobbyFont, message, new Vector2(100, 270), Color.Black); spriteBatch.End(); }
public void FindGames() { ShutDown(); try { NetworkSessionProperties searchProperties = new NetworkSessionProperties(); AvailableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, searchProperties); } catch (Exception e) { e.ToString(); } }
protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed) { this.Exit(); } if (this.IsActive) { switch (currentGameState) { case GameState.SignIn: { if (Gamer.SignedInGamers.Count < 1) { Guide.ShowSignIn(1, false); log.Add("Opened User SignIn Interface"); } else { currentGameState = GameState.SearchSession; log.Add(Gamer.SignedInGamers[0].Gamertag + " logged in - proceed to SearchSession"); } } break; case GameState.SearchSession: { Gamer.SignedInGamers[0].Presence.PresenceMode = GamerPresenceMode.Level; Gamer.SignedInGamers[0].Presence.PresenceValue = 15; AvailableNetworkSessionCollection activeSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 4, null); if (activeSessions.Count == 0) { currentGameState = GameState.CreateSession; log.Add("No active sessions found - proceed to CreateSession"); } else { AvailableNetworkSession sessionToJoin = activeSessions[0]; networkSession = NetworkSession.Join(sessionToJoin); string myString = "Joined session hosted by " + sessionToJoin.HostGamertag; myString += " with " + sessionToJoin.CurrentGamerCount.ToString() + " players"; myString += " and " + sessionToJoin.OpenPublicGamerSlots.ToString() + " open player slots."; log.Add(myString); HookSessionEvents(); currentGameState = GameState.InSession; } } break; case GameState.CreateSession: { networkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 4, 8); networkSession.AllowHostMigration = true; networkSession.AllowJoinInProgress = false; log.Add("New session created"); HookSessionEvents(); currentGameState = GameState.InSession; } break; case GameState.InSession: { networkSession.Update(); } break; } } base.Update(gameTime); }
public static void Update() { if (Controls.getInput(Action.MenuUp)) { MainClass.soundBank.PlayCue("Selection_change"); if (availableSessions != null && availableSessions.Count != 0) if (selection < 2) selection = availableSessions.Count + 1; else if (selection == 2) selection = 0; else selection--; } if (Controls.getInput(Action.MenuDown)) { MainClass.soundBank.PlayCue("Selection_change"); if (availableSessions != null && availableSessions.Count != 0) if (selection == availableSessions.Count + 1) selection = 0; else if (selection == 0) selection = 2; else selection++; } if (Controls.getInput(Action.MenuRight) || Controls.getInput(Action.MenuLeft)) { MainClass.soundBank.PlayCue("Selection_change"); if (selection == 0) selection = 1; else if (selection == 1) selection = 0; } if (Controls.getInput(Action.Select)) { MainClass.soundBank.PlayCue("Selection_choose"); if (selection == 0) try { availableSessions = NetworkSession.Find(NetworkSessionType.SystemLink, 1, null); } catch (GamerPrivilegeException) { Guide.ShowSignIn(1, false); } else if (selection == 1) { session = NetworkSession.Create(NetworkSessionType.SystemLink, 1, 12); session.AllowHostMigration = true; SetupSession(); localGamer.IsReady = true; WaitingRoom.isActive = true; isActive = false; } else { session = NetworkSession.Join(availableSessions[selection - 2]); SetupSession(); WaitingRoom.isActive = true; isActive = false; } } if(Controls.getInput(Action.Back)) { MainClass.soundBank.PlayCue("Selection_choose"); TitleScreen.isActive = true; isActive = false; selection = 0; } }
/* * Updates the lobby, detects key presses, called if we are in lobby */ void UpdateLobby() { KeyboardState keyState = Keyboard.GetState(); if (IsActive) { if (keyState.IsKeyDown(Keys.A)) { // Create a new session? CreateGame(); } else { if (keyState.IsKeyDown(Keys.R)) games = null; if (keyState.IsKeyDown(Keys.NumPad0) || keyState.IsKeyDown(Keys.D0)) JoinGame(0); if (keyState.IsKeyDown(Keys.NumPad1) || keyState.IsKeyDown(Keys.D1)) JoinGame(1); if (keyState.IsKeyDown(Keys.NumPad2) || keyState.IsKeyDown(Keys.D2)) JoinGame(2); if (keyState.IsKeyDown(Keys.NumPad3) || keyState.IsKeyDown(Keys.D3)) JoinGame(3); if (keyState.IsKeyDown(Keys.NumPad4) || keyState.IsKeyDown(Keys.D4)) JoinGame(4); if (keyState.IsKeyDown(Keys.NumPad5) || keyState.IsKeyDown(Keys.D5)) JoinGame(5); if (keyState.IsKeyDown(Keys.NumPad6) || keyState.IsKeyDown(Keys.D6)) JoinGame(6); if (keyState.IsKeyDown(Keys.NumPad7) || keyState.IsKeyDown(Keys.D7)) JoinGame(7); if (keyState.IsKeyDown(Keys.NumPad8) || keyState.IsKeyDown(Keys.D8)) JoinGame(8); if (keyState.IsKeyDown(Keys.NumPad9) || keyState.IsKeyDown(Keys.D9)) JoinGame(9); } } }
//Handle updates and redrawing for List of Available Sessions Screen public void HandleListSessions() { ListSessions.clearTexts(); ListSessions.AddText(0.5f, 0.1f, TitleFont, Color.White, "Availabe Sessions"); ListSessions.AddText(0.5f, 0.18f, TextFont, Color.White, "Press A to join"); float y = 0.2f; for (int sessionIndex = 0; sessionIndex < availableSessions.Count; sessionIndex++) { Color color = Color.White; if (sessionIndex == selectedSessionIndex) color = Color.Red; ListSessions.AddText(0.5f, y, TextFont, color, availableSessions[sessionIndex].HostGamertag); y += 0.06f; } //Handle Keyboard if (Keyboard.GetState().IsKeyDown(Keys.A)) { //Join selected Session if (availableSessions.Count > 0) { networkSession = NetworkSession.Join(availableSessions[selectedSessionIndex]); HookSessionEvents(); availableSessions.Dispose(); availableSessions = null; RNSEB.CurrentScreen = "Lobby"; } } else if (Keyboard.GetState().IsKeyDown(Keys.Up)) { if (selectedSessionIndex > 0) selectedSessionIndex--; } else if (Keyboard.GetState().IsKeyDown(Keys.Down)) { if (selectedSessionIndex < availableSessions.Count - 1) selectedSessionIndex++; } }