bitte löschen
Zuletzt bearbeitet:
Behavior b3;
b3 = new Exit();
Behavior b3 = new Exit();
Behavior b6 = new Vorwaerts.takeControl();
Behavior b5 = new Exit.takeControl();
Behavior b1 = new BlackLine.takecontrol();
Behavior [] array = {b1, b5, b6};
Arbitrator arby = new Arbitrator(array);
arby.start();
public class Stuhl{
public Stuhl(){ //Konstruktor
}
public void rueckeStuhl(){ //normale Methode
}
}
...
Stuhl stuhl = new Stuhl();
....
...
stuhl.rueckeStuhl();
...
public void start() {
while (running) {
// Find triggered behavior with highest priority
int highest = 0;
for(int i=0;i< behavior.length;i++) {
if(behavior[i].takeControl()) highest = i;
}
if ( currentBehavior == NONE | actionThread.done ) {
// No active behavior, make highest priority behavior active
currentBehavior = highest;
actionThread.execute(highest);
}
else if ( highest == currentBehavior & actionThread.done) {
// Only restart currentBehavior when it is done
actionThread.execute(highest);
}
else if ( currentBehavior < highest){
// A higher priority behavior is triggered while a lower priority
// behavior is active
actionThread.interrupt();
currentBehavior = highest;
actionThread.execute(highest);
}
Thread.yield();
}
}
import lejos.robotics.subsumption.*;
import lejos.nxt.*;
public class Exit implements Behavior{
public boolean takeControl(){
return Button.ESCAPE.isPressed();
}
public void action(){
LCD.refresh();
LCD.drawString("action Exit",0,1);
System.exit(0);
}
public void suppress(){
}
}