示例#1
0
  private boolean isWallAhead(final Commandable life) {

    final int RANGE = 5;
    final int x = life.getX();
    final int y = life.getY();

    if (life.getOrientation() == ORIENTATION.UP) {
      if (checkNewPosition(x, y - AbstractEnvironmentMap.STEP_SIZE * RANGE, life)) {
        return false;
      }
    } else if (life.getOrientation() == ORIENTATION.RIGHT) {
      if (checkNewPosition(x + AbstractEnvironmentMap.STEP_SIZE * RANGE, y, life)) {
        return false;
      }
    } else if (life.getOrientation() == ORIENTATION.DOWN) {
      if (checkNewPosition(x, y + AbstractEnvironmentMap.STEP_SIZE * RANGE, life)) {
        return false;
      }
    } else {
      if (checkNewPosition(x - AbstractEnvironmentMap.STEP_SIZE * RANGE, y, life)) {
        return false;
      }
    }
    return true;
  }
示例#2
0
 private boolean checkNewPosition(final int x, final int y, final Commandable life) {
   if (x > life.getMap().getWidth() || x < 0) {
     return false;
   } else if (y > life.getMap().getHeight() || y < 0) {
     return false;
   }
   return true;
 }