Exemplo n.º 1
0
        public MazeCell GetNextNeigbour(MazeCell cell, MonoRandom rng)
        {
            var list = new List <MazeCell>();

            if (cell.X > 0 && !CellGrid[cell.X - 1][cell.Y].Visited)
            {
                list.Add(CellGrid[cell.X - 1][cell.Y]);
            }
            if (cell.X < CellGrid.Count - 1 && !CellGrid[cell.X + 1][cell.Y].Visited)
            {
                list.Add(CellGrid[cell.X + 1][cell.Y]);
            }
            if (cell.Y > 0 && !CellGrid[cell.X][cell.Y - 1].Visited)
            {
                list.Add(CellGrid[cell.X][cell.Y - 1]);
            }
            if (cell.Y < CellGrid[cell.X].Count - 1 && !CellGrid[cell.X][cell.Y + 1].Visited)
            {
                list.Add(CellGrid[cell.X][cell.Y + 1]);
            }
            return(list.Count > 0
                ? list[rng.Next(0, list.Count)]
                : null);
        }