如何在结束之前停止方法

时间:2019-02-25 16:15:57

标签: java android loops methods

我想知道如何停止在方法中读取代码,因为我有一个具有多个if()的方法,并且如果第一个方法已完成,那么第二个方法现在也变得可读,等等:

 public void putPlayerInLadderBord() {


    if(player1Score < 0) {
        player1Score = currentPlayerScore;
        player1Name = currentPlayerName;
        player1.setText(player1Name + " - Score : " + player1Score);
    }
    if (player1Score >= 0 && player2Score < 0) {
        player2Score = currentPlayerScore;
        player2Name = currentPlayerName;
        player2.setText(player2Name + " - Score : " + player2Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score < 0) {
        player3Score = currentPlayerScore;
        player3Name = currentPlayerName;
        player3.setText(player3Name + " - Score : " + player3Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score >= 0 && player4Score < 0) {
        player4Score = currentPlayerScore;
        player4Name = currentPlayerName;
        player4.setText(player4Name + " - Score : " + player4Score);
    }
    if (player1Score >= 0 && player2Score >= 0 && player3Score >= 0 && player4Score >= 0 && player5Score < 0) {
        player5Score = currentPlayerScore;
        player5Name = currentPlayerName;
        player5.setText(player5Name + " - Score : " + player5Score);
    }
}

结果,当玩家结束游戏时,在LadderBord的每种情况下都将其得分和名称放在^^ 我想在每个if之后添加诸如stop()之类的东西,但我不知道是否有可能/我可以使用哪种语法! 谢谢

1 个答案:

答案 0 :(得分:0)

您的问题中没有循环,但是您在询问控制流程。我认为您想要if-then-else statement。或者,您可以使用the return statement。通常,the Java Tutorials是学习此类事物的绝佳资源。

相关问题