Ejemplo n.º 1
0
        private GameStateViewModel RebuildGameState(Game game)
        {
            var gameViewModel = new GameViewModel()
            {
                Id           = game.Id,
                PlayerNumber = game.PlayerNumber,
                DateCreated  = game.DateCreated,
                IsVictory    = game.IsVictory
            };

            var playerGuessList = game.Guesses
                                  .AsQueryable()
                                  .Where(guess => guess.UserId != null)
                                  .Select(GuessViewModel.FromGuess)
                                  .ToList();

            var computerGuessList = game.Guesses
                                    .AsQueryable()
                                    .Where(guess => guess.UserId == null)
                                    .Select(GuessViewModel.FromGuess)
                                    .ToList();

            var result = new GameStateViewModel()
            {
                GameViewModel   = gameViewModel,
                PlayerGuesses   = playerGuessList,
                ComputerGuesses = computerGuessList
            };

            return(result);
        }
Ejemplo n.º 2
0
        public IActionResult MovePiece([FromBody] MoveRequest moveRequest)
        {
            var endPosition   = Position.FromString(moveRequest.End);
            var startPosition = Position.FromString(moveRequest.Start);

            _gameService.ProcessMove(startPosition, endPosition);
            return(PartialView("_Board", GameStateViewModel.FromGameState(_gameService._gameState)));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Prepares the new game.
 /// </summary>
 private void PrepareNewGame()
 {
     this.gameWindowViewModels   = new List <GameWindowViewModel>();
     this.gameWindows            = new List <Window>();
     this.gameController         = null;
     this.ballAnimationTaskQueue = null;
     this.gameStateViewModel     = null;
 }
    // Constructor
    public MainPage()
    {
        InitializeComponent();
        var viewModel = new GameStateViewModel();

        viewModel.PropertyChanged += (sender, args) =>
        {
            if (viewModel.CurrentScore <= 0)
            {
                this.NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
            }
        };
        this.DataContext = viewModel;
    }
Ejemplo n.º 5
0
        public ActionResult CurrentState(int id)
        {
            GameStateViewModel viewModel = GameStateViewModel.CreateGameStateViewModel();

            viewModel.Game = gameRepository.Get(id);

            if (viewModel.Game.GameState == GameStates.Finished ||
                viewModel.Game.GameState == GameStates.Cloused)
            {
                viewModel.GameResults = gameService.GetGameResults(
                    viewModel.Game.Id).Select("", "tasks desc, bonus desc, time asc");
            }

            return(View(viewModel));
        }
        public MainViewModel()
        {
            solverTypes = new ObservableCollection <Type>();
            solverTypes.Add(typeof(NegaMaxSolver));
            solverTypes.Add(typeof(RandomSolver));
            solverTypes.Add(typeof(HumanSolver));
            solverTypes.Add(typeof(SloaneNegaMaxSolver));
            solverTypes.Add(typeof(ConfigurableNegaMaxSolver1));
            solverTypes.Add(typeof(ConfigurableNegaMaxSolver2));
            solverTypes.Add(typeof(PendulumSolver));
            solverTypes.Add(typeof(CompetitionSolver));

            GameStateViewModel           = new GameStateViewModel();
            GameStateViewModel.GameState = new GameState();

            SearchTreeViewModel = new SearchTreeViewModel();
        }
Ejemplo n.º 7
0
        public ActionResult Play()
        {
            GameStateViewModel gameState;

            var currentGame = this.games.GetCurrentGame(this.User.Identity.GetUserId());

            if (currentGame != null)
            {
                gameState = this.RebuildGameState(currentGame);
            }
            else
            {
                gameState = new GameStateViewModel();
            }


            return(View(gameState));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        /// <param name="game">The game.</param>
        /// <param name="stateViewModel">The state view model.</param>
        public void StartGame(Game game, GameStateViewModel stateViewModel)
        {
            Application.Current.MainWindow.Closing += this.OnWindowClosing;

            this.PrepareNewGame();
            this.CurrentGame = game;
            this.CurrentGame.CurrentGameState = Game.GameState.Running;
            this.gameStateViewModel           = stateViewModel;
            this.gameStateViewModel.StartGame();

            switch (this.CurrentGame.GameType)
            {
            case GameConfiguration.GameType.SinglePlayerTraining:
                this.gameController = new SinglePlayerTrainingGameController();
                break;

            case GameConfiguration.GameType.MultiPlayerGame:
                this.gameController = new MultiplayerGameController();
                break;

            default:
                this.gameController = new SinglePlayerGameController();
                break;
            }

            this.gameController.BallPlacedOnGameField += this.PlaceBallOnGameField;
            this.gameController.RoundStarted          += this.StartRound;
            this.gameController.RoundEnded            += this.RoundEnded;
            this.gameController.GameCanceled          += this.CancelGame;
            this.gameController.ErrorOccurred         += this.ErrorOccurred;

            this.gameController.StartGame();
            this.OpenGameField();

            if (this.CurrentGame.LocalPlayer.HasFirstTurn)
            {
                this.PlaceBallOnGameField();
            }
        }
 public GameStateView(GameStateViewModel viewModel)
     : this()
 {
     ViewModel = viewModel;
 }
Ejemplo n.º 10
0
        public IActionResult GetGame()
        {
            var gameState = _gameService._gameState;

            return(PartialView("_Board", GameStateViewModel.FromGameState(gameState)));
        }
Ejemplo n.º 11
0
            /// <summary>
            /// Creation method for creating the view model. Services may be passed to the creation 
            /// method to instantiate items such as lists for drop down boxes.
            /// </summary>
            public static GameStateViewModel CreateGameStateViewModel()
            {
                GameStateViewModel viewModel = new GameStateViewModel();

                return viewModel;
            }
Ejemplo n.º 12
0
            /// <summary>
            /// Creation method for creating the view model. Services may be passed to the creation
            /// method to instantiate items such as lists for drop down boxes.
            /// </summary>
            public static GameStateViewModel CreateGameStateViewModel()
            {
                GameStateViewModel viewModel = new GameStateViewModel();

                return(viewModel);
            }