public void CreateSomeFood()
        {
            IFoodFactory factory = CreateFoodFactory();
            IFood        food    = factory.CreateFood();

            food.EatIt();
        }
Esempio n. 2
0
        private void GameIsOverWhenSnakeCollidesWithBottomWall()
        {
            IFoodFactory foodFactory = null;

            "Given a food factory"
            .x(() => foodFactory = A.Fake <IFoodFactory>());
            "And given a play area with boundaries 5 and 5"
            .x(() => this.testee = new Playarea(new PlayareaSize(5, 5), foodFactory));
            "And given the snake at position row 2 and column 2"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
            "And given the snake is facing downwards"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Down));

            "When the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(3, 2)));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 2)));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake moves into wall"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should not have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 2)));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Over));
        }
Esempio n. 3
0
 public Snake(ISnakeField field, IBodyFactory bodyFactory, IFoodFactory foodFactory, int step)
 {
     Step         = step;
     Field        = field;
     _bodyFactory = bodyFactory;
     _foodFactory = foodFactory;
 }
Esempio n. 4
0
 public FoodController(IFoodFactory foodFactory, IMealFactory mealFactory, IFoodRepository repository, IMealRepository mealRepository)
 {
     this.repository = repository;
     this.mealRepository = mealRepository;
     this.foodFactory = foodFactory;
     this.mealFactory = mealFactory;
 }
Esempio n. 5
0
        private void WhenTheSnakeCollidesInFruitItGrows()
        {
            IFoodFactory foodFactory = null;

            "Given a food factory"
            .x(() => foodFactory = A.Fake <IFoodFactory>());
            "And given the food will pops up in front of snake head"
            .x(() => A.CallTo(() => foodFactory.CreateRandomFoodBetweenBoundaries(A <Position> .Ignored)).Returns(new Apple(new Position(5, 4))).Once());
            "And given a play area with boundaries 10 and 5"
            .x(() => this.testee = new Playarea(new PlayareaSize(10, 5), foodFactory));
            "And given the snake at position row 5 and column 2"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 2)));
            "And given the food is in front of the snake"
            .x(() => this.testee.Food.Position.Should().BeEquivalentTo(new Position(5, 4)));
            "And the snake is facing right wards"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Right));

            "When the snake moves into an empty place"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 3)));
            "and then the snake has not grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(0));

            "When the snake moves into the food"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 4)));
            "and then the snake has grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(1));
        }
 public Engine()
 {
     this.felineFactory = new FelineFactory();
     this.mammalFactory = new MammalFactory();
     this.birdFactory   = new BirdFactory();
     this.foodFactory   = new FoodFactory();
     this.animals       = new List <IAnimal>();
 }
 public Engine(IReader reader, IWriter writer, IAnimalFactory animalFactory, IFoodFactory foodFactory)
 {
     this.reader        = reader;
     this.writer        = writer;
     this.animalFactory = animalFactory;
     this.foodFactory   = foodFactory;
     this.animalsList   = new List <IAnimal>();
 }
 public PettingZooV70(
     Child aChild,
     IAnimalFactory factoryAnimal,
     IFoodFactory factoryFood)
 {
     TheChild  = aChild;
     TheAnimal = factoryAnimal.CreateAnimal(aChild.Age);
     TheFood   = factoryFood.CreateFood(aChild.MoneyLimit);
 }
 public RestaurantController(
     )
 {
     tables       = new List <ITable>();
     menu         = new List <IFood>();
     drinks       = new List <IDrink>();
     foodFactory  = new FoodFactory();
     drinkFactory = new DrinkFactory();
     tableFactory = new TableFactory();
 }
Esempio n. 10
0
        private void InitSnake(ISnakeField snakeField, IBodyFactory bodyFactory, IFoodFactory foodFactory)
        {
            Snake = new Snake(snakeField, bodyFactory, foodFactory, STEP);
            snakeField.Clear();
            _field.Snake     = Snake;
            Snake.OnCrashed += GameOver;
            Snake.OnEat     += SnakeOnOnEat;

            Snake.InitSnake(new Position(5 * STEP, 5 * STEP), 3);
        }
Esempio n. 11
0
 public RestaurantController(IFoodFactory foodFactory, IDrinkFactory drinkFactory,
                             ITableFactory tableFactory)
 {
     this.menu         = new List <IFood>();
     this.drinks       = new List <IDrink>();
     this.tables       = new List <ITable>();
     this.foodFactory  = foodFactory;
     this.drinkFactory = drinkFactory;
     this.tableFactory = tableFactory;
 }
Esempio n. 12
0
        public void CreateNewGame(ISkinFactory skinFactory)
        {
            IPosition    startPosition = positionRandomizer.RandomizePosition();
            SnakeBuilder builder       = new SnakeBuilder(skinFactory, startPosition);

            this.map         = map;
            this.snake       = builder.Build();
            this.foods       = new List <AbstractFood>();
            this.foodFactory = new FoodFactory(skinFactory);
        }
Esempio n. 13
0
        public Playarea(PlayareaSize size, IFoodFactory factory)
        {
            this.Size    = this.GetValidFieldSize(size);
            this.factory = factory;
            Position startPosition = new Position(this.Size.NumberOfRows / 2, this.Size.NumberOfColumns / 2);

            this.snake = new Snake(startPosition);
            this.Food  = this.GetRandomFoodInUniquePosition();
            this.SetGameState();
        }
Esempio n. 14
0
        public SnakeGame(ISnakeField field, IBodyFactory bodyFactory, IFoodFactory foodFactory, int countOfItemsInRow, int snakeSpeed)
        {
            _field             = field;
            _bodyFactory       = bodyFactory;
            _countOfItemsInRow = countOfItemsInRow;
            _snakeSpeed        = snakeSpeed;
            _foodFactory       = foodFactory;
            _snakeSpeed        = snakeSpeed;

            InitGame(field, bodyFactory, foodFactory);
        }
        public RestaurantController()
        {
            this.menu   = new List <IFood>();
            this.drinks = new List <IDrink>();
            this.tables = new List <ITable>();

            this.foodFactory  = new FoodFactory();
            this.drinkFactory = new DrinkFactory();
            this.tableFactory = new TableFactory();

            this.totalIncome = 0;
        }
Esempio n. 16
0
 public GameScene(ISnake snake, IDrawManager drawManager, IFoodFactory foodFactory, IBorder border, IScoreBoard scoreBoard, IScene pauseScene, IScene gameOverScene)
 {
     this.snake         = snake;
     this.drawManager   = drawManager;
     this.foodFactory   = foodFactory;
     this.border        = border;
     this.scoreBoard    = scoreBoard;
     this.pauseScene    = pauseScene;
     this.gameOverScene = gameOverScene;
     this.spawnedFood   = null;
     this.GameSpeed     = GameMinSpeed;
 }
Esempio n. 17
0
        private void SnakeShouldNotMoveWhenDirectionIsNeverUpdated()
        {
            // Arrange
            PlayareaSize size        = new PlayareaSize(10, 10);
            IFoodFactory foodFactory = A.Dummy <IFoodFactory>();

            this.testee = new Playarea(size, foodFactory);
            Position previousHeadPosition = this.testee.Snake.Head.Position;

            // Act
            this.testee.MoveSnakeWhenAllowed();

            // Assert
            this.testee.Snake.Head.Position.Should().BeEquivalentTo(previousHeadPosition);
        }
Esempio n. 18
0
 public PlayButton(
     IPoint topLeftPoint,
     IPoint defaultSnakePoint,
     IDrawManager drawManager,
     IFoodFactory foodFactory,
     IBorder border,
     IScene pauseScene,
     IScene gameOverScene)
     : base(topLeftPoint, ButtonText)
 {
     this.defaultSnakePoint = defaultSnakePoint;
     this.drawManager       = drawManager;
     this.foodFactory       = foodFactory;
     this.border            = border;
     this.pauseScene        = pauseScene;
     this.gameOverScene     = gameOverScene;
 }
Esempio n. 19
0
        private void SnakeCannotMoveWhenTheGameIsOver()
        {
            IFoodFactory foodFactory = null;

            "Given a food factory"
            .x(() => foodFactory = A.Dummy <IFoodFactory>());
            "And given a play area"
            .x(() => this.testee = new Playarea(new PlayareaSize(4, 5), foodFactory));
            "And given the snake at position row 2 and column 1"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
            "And the game state is start"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Start));

            "When the direction of the snake is updated for the first time"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Right));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 3)));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 4)));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake moves outside of playarea"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should not have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 4)));
            "And then the game is over"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Over));

            "When the snake tries to move"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "And when the game is over"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Over));
            "Then the snake should not have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 4)));
        }
Esempio n. 20
0
        private void SnakeCannotBeResetUnlessTheGameIsOver()
        {
            IFoodFactory foodFactory = null;

            "Given a food factory"
            .x(() => foodFactory = A.Fake <IFoodFactory>());
            "And given a play area with size 4 by 4"
            .x(() => this.testee = new Playarea(new PlayareaSize(4, 4), foodFactory));
            "And given the snake at position row 2 and column 2"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
            "And the game state is start"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Start));

            "When the direction of the snake is updated for the first time"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Right));
            "Then the game state should be running"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Running));

            "When the snake tries to be reset without being GameOver"
            .x(() => this.testee.RestartGame());
            "Then nothing happens"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));

            "when the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 3)));
            "When the snake tries to be reset without being GameOver"
            .x(() => this.testee.RestartGame());
            "Then nothing happens"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 3)));

            "When the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should not have moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 3)));
            "And then the game is over"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Over));

            "When the snake tries to be reset with the game state being GameOVer"
            .x(() => this.testee.RestartGame());
            "Then the snake is reset"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(2, 2)));
        }
 public AbstractFactoryTestCases()
 {
     animalFactory = new AnimalFactory();
     foodFactory   = new FoodFactory();
 }
Esempio n. 22
0
 public FoodController(IFoodFactory foodFactory, IFoodFactoryResolver foodFactoryResolver)
 {
     _foodFactory         = foodFactory;
     _foodFactoryResolver = foodFactoryResolver;
 }
Esempio n. 23
0
        private void GameIsOverWhenSnakeCollidesWithItself()
        {
            IFoodFactory foodFactory = null;

            "Given a food factory"
            .x(() => foodFactory = A.Fake <IFoodFactory>());
            "And given the food will pops up in front of snake head"
            .x(() => A.CallTo(() => foodFactory.CreateRandomFoodBetweenBoundaries(A <Position> .Ignored))
               .ReturnsLazily(this.CalculateNewFoodPosition));
            "And given a play area with boundaries 10 and 12"
            .x(() => this.testee = new Playarea(new PlayareaSize(10, 12), foodFactory));
            "And given the snake at position row 5 and column 6"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 6)));
            "And given the food is actually in front of the snake"
            .x(() => this.testee.Food.Position.Should().BeEquivalentTo(new Position(5, 7)));
            "And the snake is facing rightwards"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Right));


            "When the snake moves into the food"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 7)));
            "and then the snake has grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(1));

            "When the food is actually in front of the snake"
            .x(() => this.testee.Food.Position.Should().BeEquivalentTo(new Position(5, 8)));
            "And the snake moves into the food"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 8)));
            "and then the snake has grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(2));

            "When the food is actually in front of the snake"
            .x(() => this.testee.Food.Position.Should().BeEquivalentTo(new Position(5, 9)));
            "When the snake moves into the food"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 9)));
            "and then the snake has grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(3));

            "When the food is actually in front of the snake"
            .x(() => this.testee.Food.Position.Should().BeEquivalentTo(new Position(5, 10)));
            "When the snake moves into the food"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(5, 10)));
            "and then the snake has grown"
            .x(() => this.testee.Snake.Body.Count.Should().Be(4));

            "When the snake changes direction by 90 degrees"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Up));
            "And when the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 10)));

            "When the snake changes direction by 90 degrees"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Left));
            "And when the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake has moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 9)));

            "When the snake changes direction by 90 degrees"
            .x(() => this.testee.UpdateSnakeDirection(Direction.Down));
            "And when the snake moves"
            .x(() => this.testee.MoveSnakeWhenAllowed());
            "Then the snake should have collided with itself and the Game is over"
            .x(() => this.testee.CurrentGameState.Should().Be(Game.Over));
            "Then the snake has not moved"
            .x(() => this.testee.Snake.Head.Position.Should().BeEquivalentTo(new Position(4, 9)));
        }
Esempio n. 24
0
 private void InitGame(ISnakeField snakeField, IBodyFactory componentFactory, IFoodFactory foodFactory)
 {
     STEP = AdjustGameField();
     InitSnake(snakeField, componentFactory, foodFactory);
 }