/// <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> protected 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); }
/// <summary> /// Carves the maze into the grid. Uses a robot to randomly do it /// </summary> protected virtual 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]] != ExitTile.Value) { if (!IsSurrounded(this.MapArrayOfArrays, constructor, Tile.Value)) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } else { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Wall.Value; } if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] == Wall.Value && IsSurrounded(this.MapArrayOfArrays, constructor, Tile.Value) && randomSeedNumber < 2) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } if (this.IsNextTo(this.MapArrayOfArrays, constructor, ExitTile.Value)) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } } else { break; } } } }
protected override 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, 5); constructor.Move(this); int[] start = new int[2] { 1, 2 }; if (IsNextTo(this.MapArrayOfArrays, start, Wall.Value)) { this.MapArrayOfArrays[2][2] = Tile.Value; this.MapArrayOfArrays[2][3] = Tile.Value; this.MapArrayOfArrays[1][3] = Tile.Value; } if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] != ExitTile.Value) { if (!IsSurrounded(this.MapArrayOfArrays, constructor, 0)) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } else { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Wall.Value; } if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] == Wall.Value && IsSurrounded(this.MapArrayOfArrays, constructor, Tile.Value) && randomSeedNumber < 1) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } if (this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] == Tile.Value && IsSurrounded(this.MapArrayOfArrays, constructor, Wall.Value)) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Wall.Value; } if (this.IsNextTo(this.MapArrayOfArrays, constructor, ExitTile.Value)) { this.MapArrayOfArrays[constructor.Position[0]][constructor.Position[1]] = Tile.Value; } } else { continue; } } } for (int i = 1; i < MapArrayOfArrays.Length - 1; i++) { for (int j = 1; j < MapArrayOfArrays[i].Length - 1; j++) { int[] pos = new int[2] { i, j }; if (IsSurrounded(this.MapArrayOfArrays, pos, Wall.Value)) { this.MapArrayOfArrays[i][j] = Wall.Value; } } } }
/// <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> public bool IsNextTo(int[][] mapMazeArray, ConstructorDrone constructor, int value) { return(IsNextTo(mapMazeArray, constructor.Position, value)); }