コード例 #1
0
        /// <summary>
        /// Opens the game.
        /// </summary>
        private async void OpenGame()
        {
            IMainWindowContentViewModel nextWindow = null;

            foreach (var window in this.WindowSelectionViewModel.SelectedWindows)
            {
                var mapWindow = this.SelectedMap.Windows.FirstOrDefault(w => w.Id == window.Id);
                if (mapWindow != null)
                {
                    mapWindow.IsOwnWindow = window.IsChecked;
                }
            }

            if (this.gameType == GameConfiguration.GameType.MultiPlayerGame)
            {
                var loadingScreenViewModel = new LoadingScreenViewModel(Resources.WaitingForOpponent, GameConfiguration.GameType.MultiPlayerGame, true);
                GameConsoleContext.Current.GameConsoleCallback.GameStarted += loadingScreenViewModel.StartGame;
                try
                {
                    loadingScreenViewModel.CurrentGameId = await GameConsoleContext.Current.GameConsoleServiceClient.OpenGameAsync(this.SelectedMap.Id, this.WindowSelectionViewModel.SelectedWindows.Select(x => x.Id), Settings.Default.PlayerName);
                }
                catch (ServerUnavailableException ex)
                {
                    this.HandleServerException(ex);
                }

                nextWindow = loadingScreenViewModel;
            }
            else
            {
                var game = new Game();
                if (this.gameType == GameConfiguration.GameType.SinglePlayerTraining)
                {
                    game.Init(Guid.NewGuid(), this.SelectedMap, null, true, true, GameConfiguration.GameType.SinglePlayerTraining);
                }
                else
                {
                    game.Init(Guid.NewGuid(), this.SelectedMap, "José (Computer)", true, true, GameConfiguration.GameType.SinglePlayerGame);
                }

                var gameStateViewModel = new GameStateViewModel(game);
                nextWindow = gameStateViewModel;

                GameManager.Current.StartGame(game, gameStateViewModel);
            }

            this.SwitchWindowContent(nextWindow);
        }
コード例 #2
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="args">The <see cref="GameStartedEventArgs"/> instance containing the event data.</param>
        public void StartGame(object sender, GameStartedEventArgs args)
        {
            var game = new Game();

            game.Init(args.GameId, args.Map, args.Opponent, args.StartGame, this.isGameOwner, this.gameType);

            var gameStateViewModel = new GameStateViewModel(game);

            GameManager.Current.StartGame(game, gameStateViewModel);

            // Remove the current method from the GameStarted event
            GameConsoleContext.Current.GameConsoleCallback.GameStarted -= this.StartGame;

            this.SwitchWindowContent(gameStateViewModel);
            Application.Current.MainWindow.Closing -= this.OnWindowClosing;
        }