Example #1
0
        public static void Generate(Grid grid)
        {
            foreach (IEnumerable <Cell> row in grid.Rows())
            {
                var run = new List <Cell>();

                foreach (Cell cell in row)
                {
                    run.Add(cell);

                    bool atEasternBoundary  = cell.East == null;
                    bool atNorthernBoundary = cell.North == null;

                    bool shouldCloseOut = atEasternBoundary || (!atNorthernBoundary && random.Next(2) == 0);

                    if (shouldCloseOut)
                    {
                        Cell member = run.Random();
                        if (member.North != null)
                        {
                            member.Link(member.North);
                        }
                        run.Clear();
                    }
                    else
                    {
                        cell.Link(cell.East);
                    }
                }
            }
        }
Example #2
0
        public void TestLinkBidirectional()
        {
            var cell1 = new Cell();
            var cell2 = new Cell();

            cell1.Link(cell2);
            Assert.IsTrue(cell1.IsLinked(cell2));
            Assert.IsTrue(cell2.IsLinked(cell1));
        }
Example #3
0
        public void TestLink()
        {
            var cell1 = new Cell();
            var cell2 = new Cell();

            cell1.Link(cell2, false);

            Assert.IsTrue(cell1.IsLinked(cell2));
            Assert.IsFalse(cell2.IsLinked(cell1));
        }
Example #4
0
        public Cell Link(Cell cell, bool bidirectional = true)
        {
            _Links[cell] = true;

            if (bidirectional)
            {
                cell.Link(this, false);
            }

            return(this);
        }
Example #5
0
 public void Link(Cell cell, bool bidirectional = true)
 {
     if (!_links.ContainsKey(cell))
     {
         _links.Add(cell, true);
     }
     if (bidirectional)
     {
         cell.Link(this, false);
     }
 }
Example #6
0
        public Cell Link(Cell cell, bool bidirectional = true)
        {
            _Links[cell] = true;

            if (bidirectional)
            {
                cell.Link(this, false);
            }

            return this;
        }