I have the following code which relies on multiple different if-statements. I am making a Cribbage score counting app for android. The code shown is just for team Blue but whatever I end up with for team Blue will be used for teams red and green as well. What I have right now works, but it's bulky. I'm new to java and was hoping for some pointers on best practices about consolidating the code to it is easier to read and maintain.
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");
}
}
}
}
I know Boolean variables can't be used in switch statements (too bad) but is there something else similar that would help concentrate my code?
Aucun commentaire:
Enregistrer un commentaire