I am making a game and i want the game to break after executing all the statements in the if statements after score.setText(String.valueOf(gscore +"")); and continue the do while statement to do gameplay() again but how to i get the method to rerun after the score.setText(String.valueOf(gscore +"")); part of the code is executed. a break; gives me an error.
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);
}
Aucun commentaire:
Enregistrer un commentaire