示例#1
0
        public void When_a_cell_has_no_neighbors_and_a_moment_passes()
        {
            var cell = Cell.ThatsAlive();

            var cell_died = false;

            cell.When_it_dies = () => cell_died = true;
            cell.MomentPassed();

            Assert.That(cell_died, "It should die.");
        }
示例#2
0
        public void When_a_cell_has_no_neighbors_and_more_than_one_moment_passes()
        {
            var cell = Cell.ThatsAlive();

            var died_count = 0;

            cell.When_it_dies = () => died_count++;
            cell.MomentPassed();
            cell.MomentPassed();

            Assert.That(died_count, Is.EqualTo(1), "It should die only once.");
        }
        public void TouchCellAt(Location touched_location)
        {
            var was_just_born  = born_cell_locations.Any(x => x.Key.Equals(touched_location));
            var already_exists = cell_locations.Any(x => x.Key.Equals(touched_location));

            if (was_just_born)
            {
                born_cell_locations.RemoveAll(x => x.Key.Equals(touched_location));
                cell_locations.RemoveAll(x => x.Key.Equals(touched_location));
            }
            else if (already_exists)
            {
                //var touched_cell = cell_locations.Single(x => x.Key.Equals(touched_location));
                //touched_cell.Value.Touched();
            }
            else
            {
                var created_cell  = Cell.ThatsAlive();
                var cell_location = AddCellToWorld(touched_location, created_cell);
                born_cell_locations.Add(cell_location);
            }
        }