我有以下代码,它依赖于多个不同的 if 语句。我正在为 Android 制作 Cribbage 分数计数应用程序。显示的代码仅适用于蓝队,但我最终为蓝队编写的代码也将用于红队和绿队。我现在拥有的东西可以用,但它很笨重。我是 java 新手,希望获得一些有关将代码合并到更易于阅读和维护的最佳实践的指导。
if(blueTeamScore >= ENDGAMESCORE) {
String baseVictoryText = "Blue Team has won!";
TextView winningTeamTextView = (TextView) findViewById(R.id.winningTeam);
if(hasThreePlayer == false) {
winningTeamTextView.setText(baseVictoryText);
if (hasSkunk == true) {
if (redTeamScore <= 90) {
winningTeamTextView.setText(baseVictoryText + "\nAnd Red Team got Skunked");
}
}
}
if(hasThreePlayer == true) {
winningTeamTextView.setText(baseVictoryText);
if (hasSkunk == true) {
if ((redTeamScore <= 90) && (greenTeamScore <= 90)) {
winningTeamTextView.setText(baseVictoryText + "\nAnd Red and Green Teams got Skunked");
}
if ((redTeamScore <= 90) && (greenTeamScore >= 90)) {
winningTeamTextView.setText(baseVictoryText + "\nAnd Red Team got Skunked");
}
if ((redTeamScore >= 90) && (greenTeamScore <= 90)) {
winningTeamTextView.setText(baseVictoryText + "\nAnd Green Team got Skunked");
}
}
}
}
我知道布尔变量不能在 switch 语句中使用(太糟糕了),但是还有其他类似的东西可以帮助集中我的代码吗?
慕容森
撒科打诨
慕勒3428872
相关分类