Exemple #1
0
  public void move_randomly() {
    Random r = new Random();
    int valeur = r.nextInt(8);

    switch (valeur) {
      case 0:
        if (_actualPos.getX() + 4 < 800) {
          _position = "droite";
          _actualPos.setX(_actualPos.getX() + 4);
        }
        break;
      case 1:
        if (_actualPos.getX() + 4 < 800 && _actualPos.getY() + 4 < 500) {
          _position = "droite";
          _actualPos.setX(_actualPos.getX() + 4);
          _actualPos.setY(_actualPos.getY() + 4);
        }
        break;
      case 2:
        if (_actualPos.getY() + 4 < 500) {
          _actualPos.setY(_actualPos.getY() + 4);
        }
        break;
      case 3:
        if (_actualPos.getX() - 4 > 0 && _actualPos.getY() + 4 < 500) {
          _position = "gauche";
          _actualPos.setX(_actualPos.getX() - 4);
          _actualPos.setY(_actualPos.getY() + 4);
        }
        break;
      case 4:
        if (_actualPos.getX() - 4 > 0) {
          _position = "gauche";
          _actualPos.setX(_actualPos.getX() - 4);
        }
        break;
      case 5:
        if (_actualPos.getX() - 4 > 0 && _actualPos.getY() - 4 > 0) {
          _position = "gauche";
          _actualPos.setX(_actualPos.getX() - 4);
          _actualPos.setY(_actualPos.getY() - 4);
        }
        break;
      case 6:
        if (_actualPos.getY() - 4 > 0) {
          _actualPos.setY(_actualPos.getY() - 4);
        }
        break;
      case 7:
        if (_actualPos.getX() + 4 < 800 && _actualPos.getY() - 4 > 0) {
          _position = "droite";
          _actualPos.setX(_actualPos.getX() + 4);
          _actualPos.setY(_actualPos.getY() - 4);
        }
        break;
      default:
        System.out.println("NOT SUPPOSED TO HAPPEN AHDHGSGSDFHDFGHDFH");
    }
  }
Exemple #2
0
 public void move() {
   if (_toEat.getEaten()) {
     _toEat = null;
     _targetPos = null;
     _toExecute = "arret";
   } else {
     if (_targetPos.getX() == _actualPos.getX() && _targetPos.getY() == _actualPos.getY()) {
       System.out.println("Trying to eat");
       _toEat.eat();
     } else {
       // On change la position du pigeon
       // on v�rifie sur l'axe x
       if (_actualPos.getX() != _targetPos.getX()) {
         if (_actualPos.getX() < _targetPos.getX()) {
           this._position = "droite";
           this._actualPos.setX(_actualPos.getX() + 1);
         } else {
           this._position = "gauche";
           this._actualPos.setX(_actualPos.getX() - 1);
         }
       }
       // on v�rifie sur l'axe y
       if (_actualPos.getY() != _targetPos.getY()) {
         if (_actualPos.getY() < _targetPos.getY()) {
           this._actualPos.setY(_actualPos.getY() + 1);
         } else {
           this._actualPos.setY(_actualPos.getY() - 1);
         }
       }
     }
   }
 }