Пример #1
0
        public void BreakWallAndUpdateNeighbourhood(AroundCell around)
        {
            Random r = new Random();

            Cell selected = null;

            int value = 0;

            while (selected == null)
            {
                value = r.Next(4);
                switch (value)
                {
                case 0:
                    selected = around.right;
                    break;

                case 1:
                    selected = around.top;
                    break;

                case 2:
                    selected = around.bottom;
                    break;

                case 3:
                    selected = around.left;
                    break;
                }
            }

            switch (value)
            {
            case 0:
                right         = selected;
                selected.left = right;
                break;

            case 1:
                top             = selected;
                selected.bottom = top;
                break;

            case 2:
                bottom       = selected;
                selected.top = bottom;
                break;

            case 3:
                left           = selected;
                selected.right = left;
                break;
            }

            visited = true;
        }
Пример #2
0
        public AroundCell GetVisitedNeighboursAroundCell(Cell c)
        {
            AroundCell around = GetNeighboursOf(c);

            around.top    = around.top != null && around.top.visited ? around.top : null;
            around.left   = around.left != null && around.left.visited ? around.left : null;
            around.bottom = around.bottom != null && around.bottom.visited ? around.bottom : null;
            around.right  = around.right != null && around.right.visited ? around.right : null;

            return(around);
        }
Пример #3
0
        public AroundCell GetNeighboursOf(Cell c)
        {
            AroundCell around = new AroundCell();


            if (c.pos.x + 1 < size.x)
            {
                around.right = cells[c.pos.x + 1, c.pos.y];
            }
            if (c.pos.x - 1 >= 0)
            {
                around.left = cells[c.pos.x - 1, c.pos.y];
            }
            if (c.pos.y + 1 < size.y)
            {
                around.bottom = cells[c.pos.x, c.pos.y + 1];
            }
            if (c.pos.y - 1 >= 0)
            {
                around.top = cells[c.pos.x, c.pos.y - 1];
            }

            return(around);
        }