The CellUtil class

The CellUtil class is used in the Flowing water with cellular automata recipe of Chapter 3, World Building. The code to create this class is as follows:

public class CellUtil {

  private static int[][] directions = new int[][]{{0,-1},{1,-1},{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1}};
  public static int getDirection(int x, int y){
    witch(x){
      case 1:
      switch(y){
        case -1:
        return 1;
        case 0:
        return 2;
        case 1:
        return 3;
      }
      break;
      case -1:
      switch(y){
        case -1:
        return 7;
        case 0:
        return 6;
        case 1:
        return 5;
      }
      break;
      case 0:
      switch(y){
        case -1:
        return 0;
        case 0:
        return -1;
        case 1:
        return 4;
      }
      break;
    }
    return -1;
  }

  public static int[] getDirection(int dir){
   return directions[dir];
  }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.249.252