예제 #1
0
 /// <summary>
 /// Checks if a drone is surrounded by a tile value
 /// </summary>
 /// <param name="mapMazeArray"></param>
 /// <param name="constructor"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static bool IsSurrounded(int[][] mapMazeArray, ConstructorDrone constructor, int value)
 {
     return(mapMazeArray[constructor.Position[0] + 1][constructor.Position[1]] == value &&
            mapMazeArray[constructor.Position[0]][constructor.Position[1] + 1] == value &&
            mapMazeArray[constructor.Position[0]][constructor.Position[1] - 1] == value &&
            mapMazeArray[constructor.Position[0] - 1][constructor.Position[1]] == value);
 }
예제 #2
0
 /// <summary>
 /// Checks if a drone is next to a tile value
 /// </summary>
 /// <param name="mapMazeArray"></param>
 /// <param name="constructor"></param>
 /// <param name="value"></param>
 /// <returns></returns>
 private static bool IsNextTo(int[][] mapMazeArray, ConstructorDrone constructor, int value)
 {
     return(mapMazeArray[constructor.Position[0] + 1][constructor.Position[1]] == value ||
            mapMazeArray[constructor.Position[0]][constructor.Position[1] + 1] == value ||
            mapMazeArray[constructor.Position[0]][constructor.Position[1] - 1] == value ||
            mapMazeArray[constructor.Position[0] - 1][constructor.Position[1]] == value);
 }
예제 #3
0
        /// <summary>
        /// Carves the maze into the grid. Uses a robot to randomly do it
        /// </summary>
        private void BuildMazeInGrid()
        {
            ConstructorDrone constructor = new ConstructorDrone();
            Random           randomSeed  = new Random();

            for (int i = 0; i < this.MapArrayOfArrays.Length; i++)
            {
                for (int j = 0; j < this.MapArrayOfArrays[i].Length * 4; j++)
                {
                    int randomSeedNumber = randomSeed.Next(0, 3);
                    constructor.Move(this);
                    if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] != 2)
                    {
                        if (!IsSurrounded(this.MapArrayOfArrays, constructor, 0))
                        {
                            this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = 0;
                        }
                        else
                        {
                            this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = -1;
                        }
                        if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] == -1 && IsSurrounded(this.MapArrayOfArrays, constructor, 0) && randomSeedNumber < 2)
                        {
                            this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = 0;
                        }
                        if (IsNextTo(this.MapArrayOfArrays, constructor, 2))
                        {
                            this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = 0;
                        }
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }