////////////////////////////////////////////////////////////////////////////// #region Field state private void ReadFieldState(Peer peer, NetIncomingMessage message) { game = new Game(MultiplayerMode.Client); SetupField(settings.scheme); ReadFieldState(message); m_localPlayer = null; List <Player> players = game.GetPlayers().list; for (int i = 0; i < players.Count; ++i) { if (players[i].input == null) { m_localPlayer = players[i]; m_localPlayer.SetPlayerInput(InputMapping.CreatePlayerInput(InputType.Keyboard1)); m_localPlayer.input.IsActive = true; // TODO: handle console break; } } Debug.Assert(m_localPlayer != null); m_localPlayer.connection = peer.RemoteConnection; m_localPlayer.IsReady = true; m_localPlayer.needsFieldState = false; }
////////////////////////////////////////////////////////////////////////////// #region Child controllers protected override void OnControllerStop(Controller controller) { if (controller is MenuController) { MenuController.ExitCode exitCode = (MenuController.ExitCode)controller.exitCode; if (exitCode == MenuController.ExitCode.Quit) { Application.sharedApplication.Stop(); return; } switch (exitCode) { case MenuController.ExitCode.SingleStart: { StartController(new GameLobbyController()); break; } case MenuController.ExitCode.MultiplayerStart: { StartController(new MultiplayerController()); break; } case MenuController.ExitCode.DebugClientStart: { StartController(new DebugMultiplayerController(DebugMultiplayerController.Mode.Client)); break; } case MenuController.ExitCode.DebugServerStart: { StartController(new DebugMultiplayerController(DebugMultiplayerController.Mode.Server)); break; } } } else if (controller is MultiplayerController) { MultiplayerController.ExitCode exitCode = (MultiplayerController.ExitCode)controller.exitCode; if (exitCode == MultiplayerController.ExitCode.Cancel) { StartMainMenuController(); return; } switch (exitCode) { case MultiplayerController.ExitCode.Create: break; case MultiplayerController.ExitCode.Join: break; } } else if (controller is GameController) { StartMainMenuController(); } else if (controller is GameLobbyController) { GameLobbyController.ExitCode exitCode = (GameLobbyController.ExitCode)controller.exitCode; switch (exitCode) { case GameLobbyController.ExitCode.StartGame: { GameLobbyController glc = controller as GameLobbyController; Scheme selectedScheme = glc.GetSelectedScheme(); GameSettings settings = new GameSettings(selectedScheme); settings.inputEntries = glc.CreateInputEntries(); StartController(GameController.Local(settings)); break; } case GameLobbyController.ExitCode.Cancel: { StartMainMenuController(); break; } } } else if (controller is DebugMultiplayerController) { DebugMultiplayerController.ExitCode exitCode = (DebugMultiplayerController.ExitCode)controller.exitCode; switch (exitCode) { case DebugMultiplayerController.ExitCode.Cancel: { StartMainMenuController(); break; } case DebugMultiplayerController.ExitCode.ClientStarted: { ServerInfo info = controller.exitData as ServerInfo; Debug.Assert(info != null); GameSettings settings = new GameSettings(info.scheme); StartController(GameController.Client(settings)); break; } case DebugMultiplayerController.ExitCode.ServerStarted: { ServerInfo info = controller.exitData as ServerInfo; Debug.Assert(info != null); GameSettings settings = new GameSettings(info.scheme); settings.inputEntries = new GameSettings.InputEntry[] { new GameSettings.InputEntry(0, InputMapping.CreatePlayerInput(InputType.Keyboard1)) }; StartController(GameController.Server(settings)); break; } } } }