Esempio n. 1
0
        public void CanNotAddSameLife()
        {
            var sut = new GameService();

            sut.AddLife(0, 1);
            sut.AddLife(0, 1);
        }
Esempio n. 2
0
        public void CanCalculateNextGenerationWithTwoLiveCells()
        {
            var sut = new GameService();

            sut.AddLife(0, 0);
            sut.AddLife(0, 1);
            sut.CreateNextGeneration();

            Assert.AreEqual(1, sut.CurrentGenerationNumber);
            Assert.AreEqual(0, sut.AllLife.Count);
        }
Esempio n. 3
0
        public void CanAddLife()
        {
            var sut = new GameService();

            Assert.AreEqual(0, sut.AllLife.Count);
            sut.AddLife(0, 1);
            Assert.AreEqual(1, sut.AllLife.Count);
        }
Esempio n. 4
0
        public void CanCalculateNoOfNeighbours()
        {
            var sut           = new GameService();
            var lifeUnderTest = new LifeInstance(10, 10);

            sut.AddLife(lifeUnderTest);
            var result = sut.GetNumberOfNeighbours(lifeUnderTest);

            Assert.AreEqual(0, result);

            sut.AddLife(9, 10); // Add life one position to the left
            result = sut.GetNumberOfNeighbours(lifeUnderTest);
            Assert.AreEqual(1, result);

            sut.AddLife(8, 10); // Add life two positions to the left, not a neighbour
            result = sut.GetNumberOfNeighbours(lifeUnderTest);
            Assert.AreEqual(1, result);

            sut.AddLife(10, 11); // Add life one position above
            result = sut.GetNumberOfNeighbours(lifeUnderTest);
            Assert.AreEqual(2, result);
        }
Esempio n. 5
0
        public void AddLife(int xCoordinate, int yCoordinate)
        {
            // Translate from UI coordinates to game model coordinate space
            int x = xCoordinate / CanvasCellSize;
            int y = yCoordinate / CanvasCellSize;

            switch (SelectedTool)
            {
            case Tool.Cell:
                _gameService.AddLife(x, y);
                break;

            case Tool.Glider:
                _gameService.AddLife(Creatures.CreateGlider(x, y));
                break;

            case Tool.Infinite:
                _gameService.AddLife(Creatures.CreateInfinite(x, y));
                break;
            }

            DrawCurrentGeneration();
        }
Esempio n. 6
0
        static void Main(string[] args)
        {
            IEnumerable <LifeInstance> creature = CreateCreatureFromInput();

            _gameService    = new GameService();
            _timer          = new Timer();
            _timer.Elapsed += GenerationTick;
            _timer.Interval = GenerationTime;

            _gameService.AddLife(creature);

            AnsiConsole.Console.Clear(true);
            _timer.Start();

            AnsiConsole.Cursor.Hide();
            Console.Read();
        }