RunAway.java
package prey;
 
import java.util.Random;
 
public class RunAway extends Behavior {
    private Random rand = new Random();
    private int threshold = 130;
 
    public RunAway(String name, int priority) {
        super(name, priority, true);
    }
 
    @Override
    public int getMotivation() {
        int avr = Sensors.getAverageInfraredValues();
 
        if (avr > threshold) {        //Really close
            return 100;
        } else {
            return (isRunning() ? 50 : 0);
        }
 
    }
 
    @Override
    public void action() throws InterruptBehaviorException {
        Mover.forward(80, -80);
        SoundPlayer.playRunAwaySound(this, 200);
        Mover.forward(80, 80);
        SoundPlayer.playRunAwaySound(this, 1000 + rand.nextInt(500));
        Mover.forward(70, -70);
        SoundPlayer.playRunAwaySound(this, 1300);
        Mover.stop();
        HeadTurner.turnFastLeft();
        delay(500);
        HeadTurner.turnFastRight();
        delay(500);
        actionDone();
 
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License