Пример #1
0
        /// <summary>
        ///     Loads proper screens starting newly created game the game.
        /// </summary>
        /// <param name="game">Instance representing the game to be started.</param>
        private void LoadInGameScreen(Game game)
        {
            switch (game.GameType)
            {
            case GameType.SinglePlayer:
                // remove previous
                singleplayerGameOptionsControl?.Dispose();
                singleplayerGameOptionsControl = null;
                // load game screen
                inGame = new InGameControl
                {
                    Parent = singleplayerTabPage,
                    Dock   = DockStyle.Fill
                };
                break;

            case GameType.MultiplayerHotseat:
                // remove previous
                hotseatGameOptionsControl?.Dispose();
                hotseatGameOptionsControl = null;
                // load game screen
                inGame = new InGameControl
                {
                    Parent = multiplayerTabPage,
                    Dock   = DockStyle.Fill
                };
                break;

            case GameType.MultiplayerNetwork:
                // removes previous
                networkGameOptionsControl?.Dispose();
                networkGameOptionsControl = null;
                // loads game screens
                inGame = new InGameControl
                {
                    Parent = multiplayerTabPage,
                    Dock   = DockStyle.Fill
                };
                break;
            }
            inGame.Initialize(game);
            inGame.Show();
        }
Пример #2
0
        /// <summary>
        ///     Resets previously loaded multiplayer control and loads new, resetted one.
        /// </summary>
        private void LoadMultiplayerControls()
        {
            void LoadHotseatControls()
            {
                hotseatGameOptionsControl?.Dispose();
                networkGameOptionsControl?.Dispose();
                networkGameOptionsControl = null;
                hotseatGameOptionsControl = new HotseatGameOptionsControl
                {
                    Parent = multiplayerTabPage,
                    Dock   = DockStyle.Fill
                };
                hotseatGameOptionsControl.Show();

                hotseatGameOptionsControl.OnGameStarted += StartNewGame;
                hotseatGameOptionsControl.OnGameLoaded  += LoadGame;
            }

            void LoadNetworkControls()
            {
                networkGameOptionsControl?.Dispose();
                hotseatGameOptionsControl?.Dispose();
                hotseatGameOptionsControl = null;
                networkGameOptionsControl = new NetworkGameOptionsControl
                {
                    Parent = multiplayerTabPage,
                    Dock   = DockStyle.Fill
                };
                networkGameOptionsControl.OnGameCreated += CreateNewGame;
                networkGameOptionsControl.Show();
            }

            GameTypeChoiceForm gameTypeChoiceForm = new GameTypeChoiceForm();
            DialogResult       dialogResult       = gameTypeChoiceForm.ShowDialog();

            switch (dialogResult)
            {
            case DialogResult.OK:
                switch (gameTypeChoiceForm.MultiplayerGameType)
                {
                case GameType.MultiplayerHotseat:
                    LoadHotseatControls();
                    break;

                case GameType.MultiplayerNetwork:
                    // network => find out if user is logged
                    if (TryToLogIn())
                    {
                        LoadNetworkControls();
                    }
                    else
                    {
                        typeGameChoiceTabControl.SelectedIndex = previousTabSelectedIndex;
                    }
                    break;

                default:
                    // return back to previous stage
                    typeGameChoiceTabControl.SelectedIndex = previousTabSelectedIndex;
                    return;
                }
                break;

            case DialogResult.Cancel:
            default:
                // TODO: invokes select index event, I want it to return back to previous index without deleting it
                typeGameChoiceTabControl.SelectedIndex = previousTabSelectedIndex;
                return;
            }
        }