我一直在做这个 yahtzee 项目并且遇到了问题。dice_number 数组似乎没有得到随机生成的值。oneScore TextView 始终显示“--”。我正在发布我的代码。提前感谢您提供的任何帮助。另外,如果您需要查看更多代码,请告诉我。
switch (v.getId()) {
case R.id.rollBtn:
for(i = 0; i < 5; i++){
randnum = random.nextInt(5);
if(i == 0){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
else if(i == 1){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
else if(i == 2){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
else if(i == 3){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
else if(i == 4){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
else if(i == 5){
images[i].setImageResource(image_array[randnum]);
dice_number[i] = randnum;
}
}
break;
case R.id.onesBtn:
for (i = 0; i < 5; i++)
{
if (dice_number[i] == 1) {
dice_count[0] += 1;
oneScore.setText(Integer.toString(dice_count[0]));
}
else
oneScore.setText("--");
}