示例#1
0
    WallIndex FindOppositeDirection(WallIndex wallIndex)
    {
        WallIndex oppositeDirection = WallIndex.NorthWall;

        switch ((int)wallIndex)
        {
        case 0:
        {
            oppositeDirection = WallIndex.SouthWall;
            break;
        }

        case 1:
        {
            oppositeDirection = WallIndex.WestWall;
            break;
        }

        case 2:
        {
            oppositeDirection = WallIndex.NorthWall;
            break;
        }

        case 3:
        {
            oppositeDirection = WallIndex.EastWall;
            break;
        }
        }

        return(oppositeDirection);
    }
示例#2
0
 public void RemoveMazeCell(int cellIndex, WallIndex wallIndex)
 {
     if (cellIndex >= 0 && cellIndex < _mazeCells.Count)
     {
         _mazeCells[cellIndex].RemoveWall(wallIndex);
     }
 }
示例#3
0
    public void IsBorderCellTest(int maxY, int maxX,
                                 int cellIndex, WallIndex wallIndex, bool expectedResult)
    {
        // Arrange
        MazeShaperZ shaper = new MazeShaperZ(maxY, maxX);

        // Act
        bool result = false;

        if (wallIndex == WallIndex.NorthWall)
        {
            result = shaper.IsNorthBorderCell(cellIndex);
        }

        if (wallIndex == WallIndex.EastWall)
        {
            result = shaper.IsEastBorderCell(cellIndex);
        }

        if (wallIndex == WallIndex.SouthWall)
        {
            result = shaper.IsSouthBorderCell(cellIndex);
        }

        if (wallIndex == WallIndex.WestWall)
        {
            result = shaper.IsWestBorderCell(cellIndex);
        }

        // Assert
        Assert.That(expectedResult, Is.EqualTo(result));
    }
示例#4
0
 public void SetOuterWallAsBorder(WallIndex wallIndex)
 {
     if ((int)wallIndex >= 0 && (int)wallIndex < _mazeWalls.Count)
     {
         _mazeWalls[(int)wallIndex].IsOuterBorderWall = true;
     }
 }
示例#5
0
 public bool DoesWallExist(int cellIndex, WallIndex wallIndex)
 {
     if ((int)wallIndex >= 0 && (int)wallIndex < _mazeCells.Count)
     {
         return(_mazeCells[cellIndex].DoesWallExist(wallIndex));
     }
     return(false);
 }
示例#6
0
    public bool DoesWallExist(WallIndex wallIndex)
    {
        if ((int)wallIndex >= 0 && (int)wallIndex < _mazeWalls.Count)
        {
            return(_mazeWalls[(int)wallIndex].gameObject.activeSelf);
        }

        return(false);
    }
示例#7
0
    public void FindAdjacentCellTest(int maxY, int maxX,
                                     int cellIndex, WallIndex wallIndex, int expected)
    {
        // Arrange
        MazeShaperZ shaper = new MazeShaperZ(maxY, maxX);

        // Act
        int adjacentResult = shaper.FindAdjacentCellIndex(cellIndex, wallIndex);

        // Assert
        Assert.That(adjacentResult, Is.EqualTo(expected));
    }
示例#8
0
 public void RemoveWall(WallIndex wallIndex)
 {
     if ((int)wallIndex >= 0 && (int)wallIndex < _mazeWalls.Count)
     {
         if (!_mazeWalls[(int)wallIndex].IsOuterBorderWall)
         {
             _mazeCell.RemoveWall(wallIndex);
             _mazeWalls[(int)wallIndex].RemoveWall();
             _mazeWalls[(int)wallIndex].gameObject.SetActive(false);
         }
     }
 }
示例#9
0
    public int FindAdjacentCellIndex(int cellIndex, WallIndex wallIndexOfInterest)
    {
        int oppositeCellIndex = -1;

        switch ((int)wallIndexOfInterest)
        {
        case 0:
        {
            if (!IsNorthBorderCell(cellIndex))
            {
                oppositeCellIndex = cellIndex + 1;
            }
            break;
        }

        case 1:
        {
            if (!IsEastBorderCell(cellIndex))
            {
                oppositeCellIndex = cellIndex + _sizeNorth;
            }
            break;
        }

        case 2:
        {
            if (!IsSouthBorderCell(cellIndex))
            {
                oppositeCellIndex = cellIndex - 1;
            }
            break;
        }

        case 3:
        {
            if (!IsNorthBorderCell(cellIndex))
            {
                oppositeCellIndex = cellIndex - _sizeNorth;
            }
            break;
        }
        }

        return(oppositeCellIndex);
    }
示例#10
0
    public void RemoveOtherSideOfWall(int cellIndex, WallIndex wallIndex)
    {
        int oppositeCellIndex = _mazeShaper.FindAdjacentCellIndex(cellIndex, wallIndex);

        if (oppositeCellIndex < 0 || oppositeCellIndex >= _mazeCells.Count)
        {
            return;
        }

        WallIndex oppositeDirection = FindOppositeDirection(wallIndex);

        if ((int)oppositeDirection >= 0 && (int)oppositeDirection < _mazeCells.Count)
        {
            if (_mazeCells[oppositeCellIndex].DoesWallExist(oppositeDirection))
            {
                _mazeCells[oppositeCellIndex].RemoveWall(oppositeDirection);
            }
        }
    }
示例#11
0
        // switch to touching wall if it exists
        // otherwise return current wall
        private WallIndex FindNextWall(WallIndex current)
        {
            WallIndex other = current;

            Point p = wall2point[current.Wall, current.Corner];

            List <WallIndex> pointWalls = point2wall[p];

            foreach (WallIndex index in pointWalls)
            {
                if (index.Wall != current.Wall)
                {
                    other = index;
                    break;
                }
            }

            return(other);
        }
示例#12
0
 public void RemoveWall(WallIndex wallIndex)
 {
     Walls.Remove(wallIndex);
 }
示例#13
0
 private Point LookupPoint(WallIndex index)
 {
     return(wall2point[index.Wall, index.Corner]);
 }
示例#14
0
        public void Generate()
        {
            wall2point = new Point[maze.Length, 4];

            for (int iwall = 0; iwall < maze.Length; ++iwall)
            {
                Transform wall = maze[iwall];

                for (int icorner = 0; icorner < 4; ++icorner)
                {
                    Point p = Corner(wall, icorner);

                    if (points.ContainsNear(p))
                    {
                        p = points.GetNear(p);
                    }
                    else
                    {
                        points.Add(p);

                        List <WallIndex> walls = new List <WallIndex>();
                        point2wall.Add(p, walls);
                    }

                    point2wall[p].Add(new WallIndex(iwall, icorner));
                    wall2point[iwall, icorner] = p;
                }
            }

            WallIndex currentWall = new WallIndex(0, 2);
            Point     current     = vertices.AddNear(LookupPoint(currentWall));
            Point     first       = current;

            Point     prev     = null;
            WallIndex peekWall = null;
            Point     peek     = null;

            for (int ii = 0; ii < 100; ++ii)
            {
                prev = current;

                currentWall = FindNextWall(currentWall).Rotate;

                current = LookupPoint(currentWall);
                if (current.IsCoincident(first))
                {
                    edges.Add(new PolygonEdge(prev, first));
                    break;
                }

                // combine parallel wall edges
                for (int jj = 0; jj < 5; ++jj)
                {
                    peekWall = FindNextWall(currentWall).Rotate;

                    peek = LookupPoint(peekWall);
                    Vector v0 = current - prev;
                    Vector v1 = peek - current;

                    if (v1.IsParallel(v0)) // (peek - current).IsParallel(current - prev))
                    {
                        currentWall = peekWall;
                        current     = peek;
                    }
                    else
                    {
                        break;
                    }
                }

                current = vertices.AddNear(current);
                edges.Add(new PolygonEdge(prev, current));
            }

            DetermineBounds();
        }
示例#15
0
        //**********************************************************
        //** methods:
        //**********************************************************

        public void RemoveWall(WallIndex index) => Walls[(int)index] = false;