删除条件语句

时间:2013-06-25 10:52:11

标签: java if-statement methods conditional

我想知道如何删除条件语句并将其替换为方法。对于没有监听器的代码,我可以做到。但这一个有听众事件(arg0),这让我感到困惑。 fyi,这段代码在Main Class中,我希望将这些代码从主类中删除。

感谢您的帮助!!

@Override
public void onMotionSensingEvent( MotionSensingEvent arg0) {

    double gradient = 1.38;
    double speed;

    float testpitch = 0;
    testpitch = arg0.getOrientation().getPitch();

    float testroll = 0;
    testroll = arg0.getOrientation().getRoll();

    if (testroll > 16 && flyingControl)
    {
        speed = gradient*testroll-22.1;
        System.out.println("kanan = " + speed);
        ardrone.goRight(speed);
    }
    else if (testroll < (-24) && flyingControl)
    {
        speed = gradient*testroll*-1 - 22.1;
        System.out.println("kiri = " + speed);
        ardrone.goLeft(speed);
    }
    else if (testpitch < (-20) && flyingControl)
    {
        System.out.println("go up");
        ardrone.up();
    }
    else if (testpitch > 20 && flyingControl)
    {
        System.out.println("go down");
        ardrone.down();
    }
    else
    {
        ardrone.stop();
    }

}

0 个答案:

没有答案