Exemplo n.º 1
0
        public List <Orientation> WhereCanIGo(int i, int j)
        {
            List <Orientation> orients = new List <Orientation>();

            if (i - 2 >= 0 && !MazeMatrix[i - 2, j].IsUsed && MazeMatrix[i - 2, j].Value == CellType.Empty)
            {
                orients.Add(Orientation.Up);
            }

            if (j + 2 < MazeMatrix.GetLength(1) && !MazeMatrix[i, j + 2].IsUsed && MazeMatrix[i, j + 2].Value == CellType.Empty)
            {
                orients.Add(Orientation.Right);
            }

            if (i + 2 < MazeMatrix.GetLength(0) && !MazeMatrix[i + 2, j].IsUsed && MazeMatrix[i + 2, j].Value == CellType.Empty)
            {
                orients.Add(Orientation.Down);
            }

            if (j - 2 >= 0 && !MazeMatrix[i, j - 2].IsUsed && MazeMatrix[i, j - 2].Value == CellType.Empty)
            {
                orients.Add(Orientation.Left);
            }


            return(orients);
        }
    private void TryToMove(Vector2 actualPos, Vector2 movement, out Vector2 newPos, bool allowMoveOverPath)
    {
        Vector2 initialPos = actualPos;

        newPos = actualPos + movement;
        //Verify that new pos is inside matrix
        if ((newPos.x > -1 && newPos.x < MazeMatrix.GetLength(0)) && (newPos.y > 0 && newPos.y < MazeMatrix.GetLength(1)))
        {
            //verify that newPos is a wall
            if (MazeMatrix[(int)newPos.x, (int)newPos.y] == (int)MazeElement.Wall)
            {
                newPos = initialPos;
            }

            if (!allowMoveOverPath)
            {
                if (pathMemory[(int)newPos.x, (int)newPos.y] == (int)MazeElement.Path)
                {
                    newPos = initialPos;
                }
            }
        }
        else
        {
            newPos = initialPos;
        }
    }
Exemplo n.º 3
0
 public void FillMaze()
 {
     for (int i = 0; i < MazeMatrix.GetLength(0); i++)
     {
         for (int j = 0; j < MazeMatrix.GetLength(1); j++)
         {
             if (i % 2 == 1 && j % 2 == 1)
             {
                 MazeMatrix[i, j] = new Cell(i, j, CellType.Empty);
             }
             else
             {
                 MazeMatrix[i, j] = new Cell(i, j, CellType.Wall);
             }
         }
     }
 }
Exemplo n.º 4
0
 public void ResetMaze()
 {
     for (int i = 0; i < MazeMatrix.GetLength(0); i++)
     {
         for (int j = 0; j < MazeMatrix.GetLength(1); j++)
         {
             if (i % 2 == 1 && j % 2 == 1)
             {
                 MazeMatrix[i, j].SetValues(i, j, CellType.Empty);
             }
             else
             {
                 MazeMatrix[i, j].SetValues(i, j, CellType.Wall);
             }
         }
     }
 }