I want to use switch instead of if-else as I've that it's better when there are many if-else. The problem is that I've multiple arguments, so I don't know how to handle that.
Here are my if-else's:
if(frame.height()/2 + margin < pt.y){
System.out.println("down");
drone.getCommandManager().down(20).doFor(100);
drone.getCommandManager().hover();
}
else if(frame.height()/2 - margin > pt.y){
System.out.println("up");
drone.getCommandManager().up(20).doFor(100);
drone.getCommandManager().hover();
}
else if(frame.width()/2+margin < pt.x){
drone.getCommandManager().spinRight(30).doFor(33);
drone.getCommandManager().hover();
System.out.println("RIGHT");
}
else if(frame.width()/2-margin > pt.x){
drone.getCommandManager().spinLeft(30).doFor(33);
drone.getCommandManager().hover();
System.out.println("LEFT");
}
else if(frame.width()/2+margin > pt.x && frame.width()/2-margin<pt.x){
System.out.println("GO");
drone.getCommandManager().forward(30).doFor(time+2000);
drone.getCommandManager().hover();
}
else{
drone.getCommandManager().hover();
}
Aucun commentaire:
Enregistrer un commentaire