Example #1
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);
         }
       }
     }
   }
 }
Example #2
0
 public synchronized void set_target(IFood food) {
   _toEat = food;
   _targetPos = _toEat.getPos();
 }