Advertisement
Guest User

Untitled

a guest
Dec 7th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. public int checkForIslands(Tile[][] tiles) {
  2.         int islands = 0;
  3.        
  4.         //create temparray and init
  5.         Tile[][] t = new Tile[tiles.length][tiles[0].length];
  6.         for(int i = 0; i < t.length;i++) {
  7.             for(int j = 0; j < t[0].length; j++) {
  8.                 t[i][j] = new Tile(i,j,TileType.EMPTY);
  9.             }
  10.         }
  11.         //Copy TileType
  12.         for(int i = 0; i < t.length;i++) {
  13.             for(int j = 0; j < t[0].length; j++) {
  14.                 t[i][j].setType(tiles[i][j].getType());
  15.             }
  16.         }
  17.         for(int i = 0; i < t.length; i++) {
  18.             for(int j = 0; j < t[0].length; j++) {
  19.                 islands += checkNeighbours(i,j,t);
  20.             }
  21.         }  
  22.         return islands;
  23.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement