/// <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);
        }
Beispiel #2
0
        /// <summary>
        /// Joins the game.
        /// </summary>
        private void JoinGame()
        {
            try
            {
                var loadingScreen = new LoadingScreenViewModel(Resources.JoiningGameMessage, GameConfiguration.GameType.MultiPlayerGame)
                {
                    CurrentGameId = this.SelectedLobbyGame.Id
                };

                GameConsoleContext.Current.GameConsoleCallback.GameStarted += loadingScreen.StartGame;
                GameConsoleContext.Current.GameConsoleServiceClient.JoinGame(this.SelectedLobbyGame.Id, Settings.Default.PlayerName);
                this.SwitchWindowContent(loadingScreen);
            }
            catch (FaultException <GameNotOpenException> )
            {
                MessageBox.Show(Resources.GameAlreadyOpened, Resources.Error);
            }
            catch (ServerUnavailableException ex)
            {
                this.HandleServerException(ex);
            }
        }