这是一个 yahtzee 游戏,这个方法应该计算并返回五个骰子的值。但这是一种愚蠢的做法吗,有一个 switch 语句通过参数传递用户选择的类别,然后为每个可能的类别进行 for 循环。有没有比我的设计理念更容易做到这一点的方法?
private int assignScoreToCategory(int category)
{
int computedScore = 0;
println("dice: "+dice1+" "+dice2+" "+dice3+" "+dice4+" "+dice5);
// Switches on the category the user has selected.
switch (category)
{
case ONES:
for (int i = 0; i < 4; i++){
if (diceArray[i] == ONES){
println(computedScore);
computedScore++;
}
}break;
case TWOS:
break;
case THREES: break;
case FOURS: break;
case FIVES: break;
case SIXES: println("cat 6"); break;
case UPPER_SCORE: break;
case UPPER_BONUS: break;
case THREE_OF_A_KIND: break;
case FOUR_OF_A_KIND: break;
case FULL_HOUSE: break;
case SMALL_STRAIGHT: break;
case YAHTZEE: break;
case CHANCE: break;
case LOWER_SCORE: break;
case TOTAL: break;
default: return 0;
}
return computedScore;
}