Example #1
0
 public Engine(IReader reader, IWriter writer, IAnimalCreator animalCreator, IFoodCreator foodCreator)
 {
     this.reader        = reader;
     this.writer        = writer;
     this.animals       = new List <IAnimal>();
     this.animalCreator = animalCreator;
     this.foodCreator   = foodCreator;
 }
Example #2
0
        public MainViewModel(
            IKeyboardConfigurationProvider keyboardConfigurationProvider,
            IGameConfigurationProvider gameConfigurationProvider,
            ICollisionDetector collisionDetector,
            IFoodCreator foodCreator,
            IImageDownloader imageDownloader,
            IDirectionChangeDetector directionChangeDetector
            )
        {
            _keyboardConfigurationProvider = keyboardConfigurationProvider;
            _gameConfigurationProvider     = gameConfigurationProvider;
            _collisionDetector             = collisionDetector;
            _foodCreator             = foodCreator;
            _imageDownloader         = imageDownloader;
            _directionChangeDetector = directionChangeDetector;

            _up    = _keyboardConfigurationProvider.Up;
            _down  = _keyboardConfigurationProvider.Down;
            _left  = _keyboardConfigurationProvider.Left;
            _right = _keyboardConfigurationProvider.Right;

            _allowedMovementKeysMap = new Dictionary <Key, SnakeDirection>()
            {
                { _up, SnakeDirection.Up },
                { _down, SnakeDirection.Down },
                { _left, SnakeDirection.Left },
                { _right, SnakeDirection.Right }
            };

            OnKeyDownCommand = new RelayCommandGeneric <Key>(p => OnKeyDown(p), p => true);

            timer.Interval = TimeSpan.FromMilliseconds(1000 / gameConfigurationProvider.SnakeSpeed);
            timer.Tick    += OnTimerTick;
            timer.Start();

            _objectSizeX         = _gameConfigurationProvider.GameObjectSizeX;
            _objectSizeY         = _gameConfigurationProvider.GameObjectSizeY;
            _maxXLogicalPosition = GameAreaDimensionX / _objectSizeX;
            _maxYLogicalPosition = GameAreaDimensionY / _objectSizeY;

            StartGame();
        }