示例#1
0
 /**
  * @param minValue
  * @param maxValue
  */
 public void onAllValidPositions(
     int minValue, int maxValue, Callback3<Integer, Integer, Integer> cb) {
   for (int x = 0; x < sideLen; x++) {
     for (int y = 0; y < sideLen; y++) {
       int value = this.data.$get(x).$get(y);
       if (value >= minValue && value <= maxValue) {
         cb.$invoke(x, y, value);
       }
     }
   }
 }
示例#2
0
  public boolean nextRandomPosition(
      Callback3<Integer, Integer, Object> cb, Object arg, int minValue) {
    int n = JSGlobal.parseInt(Math.random() * sideLen, 10);
    for (int x = 0; x < sideLen; x++) {
      for (int y = 0; y < sideLen; y++) {
        if (this.data.$get(x).$get(y) >= minValue) {
          n--;

          if (n < 0) {
            cb.$invoke(x, y, arg);
            return true;
          }
        }
      }
    }

    return false;
  }
示例#3
0
  public void nextValidPosition(
      int x,
      int y,
      int minValue,
      boolean walkLeft,
      Callback3<Integer, Integer, Object> cb,
      Object arg) {
    x = x - this.centerX;
    y = y - this.centerY;

    if (x < 0 || y < 0 || x >= sideLen || y >= sideLen) {
      if (walkLeft) {
        // start bottom right
        x = sideLen - 1;
        y = sideLen - 1;

      } else {
        // start top left
        x = 0;
        y = 0;
      }
    }

    // walk to the next position
    int mod = (walkLeft) ? -1 : +1;
    y += mod;
    for (; (walkLeft) ? x >= 0 : x < sideLen; x += mod) {
      for (; (walkLeft) ? y >= 0 : y < sideLen; y += mod) {
        if (this.data.$get(x).$get(y) >= minValue) {
          // valid position
          cb.$invoke(x, y, arg);
          return;
        }
      }

      y = (walkLeft) ? sideLen - 1 : 0;
    }
  }