Пример #1
0
        public void GenFromFile(System.Drawing.Bitmap img)
        {
            Source = TileGridSource.FILE;

            if(img.Width != Width || img.Height != Height){
                GenEmptyGrid();
                return;
            }

            for (int x = 0; x < Width; x++){
                for (int y = 0; y < Height; y++){
                    System.Drawing.Color pixel = img.GetPixel(x, y);

                    if (pixel.R == 0 && pixel.G == 0 && pixel.B == 0){ //#000000 - Black
                        Grid[x, y] = new Tile(TileType.CLOSED);
                    } else if(pixel.R == 255 && pixel.G == 255 && pixel.B == 255) { //#FFFFFF - White
                        Grid[x, y] = new Tile(TileType.OPEN);
                    } else if(pixel.R == 255 && pixel.G == 0 && pixel.B == 0) { //#FF0000 - Red
                        Grid[x, y] = new Tile(TileType.END);
                    } else if(pixel.R == 0 && pixel.G == 255 && pixel.B == 0) { //#00FF00 - Green
                        Grid[x, y] = new Tile(TileType.START);
                    } else {
                        Grid[x, y] = new Tile(TileType.OPEN);
                    }
                }
            }

            if(!IsValidGrid()){
                GenEmptyGrid();
            }
        }
Пример #2
0
        public void GenRandomGrid(Double closedPercentage)
        {
            Source = TileGridSource.RANDOM;
            Random ran = new Random();
            for(int x = 0; x < Width; x++) {
                for(int y = 0; y < Height; y++) {
                    if(ran.NextDouble() > (closedPercentage / 100)) {
                        Grid[x, y] = new Tile(TileType.OPEN);
                    } else {
                        Grid[x, y] = new Tile(TileType.CLOSED);
                    }
                }
            }
            Grid[ran.Next(Width), ran.Next(Height)] = new Tile(TileType.START);
            Grid[ran.Next(Width), ran.Next(Height)] = new Tile(TileType.END);

            if(!IsValidGrid()) {
                GenRandomGrid(closedPercentage);
            }
        }
Пример #3
0
 public void GenEmptyGrid()
 {
     Source = TileGridSource.EMPTY;
     for(int x = 0; x < Width; x++) {
         for(int y = 0; y < Height; y++) {
             Grid[x, y] = new Tile(TileType.OPEN);
         }
     }
     Grid[1, 1] = new Tile(TileType.START);
     Grid[Width - 2, Height - 2] = new Tile(TileType.END);
     Grid[Width / 2, Height / 2] = new Tile(TileType.CLOSED);
 }