public SapperWindowViewModel([Required] IGameFieldFactory fieldFactory)
        {
            _fieldFactory = fieldFactory;
            MinefieldSize = DefaultMinefieldSize;
            MaxMineCount  = DefaultMaxMineCount;

            // There is already a request to create a new field when the window is loaded,
            // but here I shouldn't know about it. I just want to avoid NullReferenceException
            Minefields = CreateMinefieldCellCollection();

            StatusLog = new ReactiveList <string>();
            this.WhenAnyValue(vm => vm.Status)
            .Subscribe(status =>
            {
                var gameStatusMessage = status.GetGameStatus();
                StatusLog.Clear();
                StatusLog.Add(gameStatusMessage);
            });

            SetupNewGameCommand();
        }
Ejemplo n.º 2
0
        private async Task LoadAsync()
        {
            var tasks = new List <Task>
            {
                Task.Run(() =>
                {
                    _randomGenerator = new RandomGenerator(2);

                    _gameFieldFactory   = new GameFieldFactory(GameSettings, _randomGenerator);
                    _gameField          = _gameFieldFactory.GetRandomField(GameSettings.MapWidth, GameSettings.MapHeight, 0.9d);
                    _gameFieldComponent = new GameFieldComponent(_gameField,
                                                                 new GameFieldGraphicsComponent(_gameField, GraphicsSystem.GraphicsSettings, GraphicsSystem,
                                                                                                GameSettings));

                    _snakeEntity = new SnakeEntity(Logger, _gameField, GameSettings);
                    _snakeEntity.Grow();
                    _snakeMovementComponent =
                        new SnakeMovementTurnBased(_snakeEntity, _gameField, GameSettings,
                                                   new SnakeControlKeys(Keys.Up, Keys.Down, Keys.Left, Keys.Right));
                    _snakeGameComponent = new SnakeGameComponent(_snakeEntity,
                                                                 new SnakeGraphicsComponent(_snakeEntity, GraphicsSystem, _snakeMovementComponent, _gameField),
                                                                 _snakeMovementComponent, Logger);

                    _foodManager = new FoodManager(Game, _gameField, GameSettings, GraphicsSystem, Logger, _snakeEntity);
                    _foodManager.Add(_foodManager.GenerateRandomFood());

                    #region Common

                    _gamePoints  = new GamePoints(GameSettings.RemainingLives);
                    _gameManager = new GameManager(Logger, _foodManager, _snakeGameComponent, _gameField, GameSettings,
                                                   _gamePoints, _snakeEntity, SceneManager, Game, GraphicsSystem, GameKeys)
                    {
                        Enabled = true
                    };

                    #endregion Common

                    grayScaleEffect = Game.Content.Load <Effect>("Effects/grayscale");
                    shadeEffect     = Game.Content.Load <Effect>("Effects/dark");

                    #region UI components

                    _fpsCounter = new FpsCounter(new Vector2(Game.GraphicsDevice.Viewport.Width - 50, 0), GraphicsSystem.SpriteFont, Color.Black);

                    var pointsCounterPosition = Vector2.Add(new Vector2(_gameField.Bounds.Right, _gameField.Bounds.Top),
                                                            new Vector2(10, 0));
                    _pointsCounterComponent = new PointsCounterComponent(pointsCounterPosition, GraphicsSystem, _gamePoints);

                    var remainingLivesPosition = Vector2.Add(new Vector2(_gameField.Bounds.Right, _gameField.Bounds.Top),
                                                             new Vector2(10, 25));
                    _remainingLivesComponent = new RemainingLivesComponent(remainingLivesPosition, GraphicsSystem, _gamePoints);

                    _debugInfoPanelComponent = new DebugInfoPanelComponent(GraphicsSystem, GameSettings, _gameManager);

                    #endregion UI components
                }),

                Task.Delay(500)
            };

            await Task.WhenAll(tasks.ToArray());

            IsLoaded = true;
        }
Ejemplo n.º 3
0
 public TurnBasedGameFieldFacade(IGameFieldFactory gameFieldFactory, ISerializer <GameFieldSnapshot> serializer)
 {
     _gameFieldFactory = gameFieldFactory;
     _serializer       = serializer;
 }