如何在do语句中打破if语句

时间:2017-03-05 06:36:02

标签: java android if-statement

我正在制作游戏,我希望游戏在执行score.setText(String.valueOf(gscore +""));之后的if语句中的所有语句后中断并继续do while语句再次执行gameplay()但是如何获得在执行代码的score.setText(String.valueOf(gscore +""));部分之后重新运行的方法。休息;给我一个错误。

protected void gamePlay(){
do{
    tgc.setY(tblc.getY());
    tbc.setY(tblc.getY());
    trc.setY(tblc.getY());
    tyc.setY(tblc.getY());


    x = (int)(Math.random()*(4) );

    if(x == 0){
        tbc.setVisibility(View.VISIBLE);
    }
    else if(x == 1){
        tgc.setVisibility(View.VISIBLE);
    }
    else if(x == 2){
        trc.setVisibility(View.VISIBLE);
    }
    else if(x == 3){
        tyc.setVisibility(View.VISIBLE);
    }
    rLayout.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            if(x == 0){

                if(tbc.getY() < bc.getY()+50 && tbc.getY() > bc.getY()-50){
                    gscore = gscore+1;
                    score.setText(String.valueOf(gscore +""));

                }
                else{
                    gameLost();
                }
            }
            else if(x==1)
                if(tbc.getY() < gc.getY()+50 && tbc.getY() > gc.getY()-50){
                    gscore = gscore+1;
                    score.setText(String.valueOf(gscore+"" ));

                }
                else{
                    gameLost();

                }
            else if(x==2)
                if(tbc.getY() < rc.getY()+50 && tbc.getY() > rc.getY()-50){
                    gscore = gscore+1;
                    score.setText(String.valueOf(gscore +""));



                }
                else{
                    gameLost();

                }
            else if(x==3)
                if(tbc.getY() < yc.getY()+50 && tbc.getY() > yc.getY()-50){
                    gscore = gscore+1;
                    score.setText(String.valueOf(gscore +""));



                }
                else{
                    gameLost();
                }
        }
    });
}while(checkGameLost()==false);
}

0 个答案:

没有答案