下面的代码是计算机玩游戏的部分代码。问题是计算机播放时 comp_overall_score 没有更新。请帮忙。
while(comp_turn_score < 20)
{
//roll logic
rollValue = rolldice();
Log.v("\nComputer Roll:",Integer.toString(rollValue));
if(rollValue != 1)
{
comp_turn_score += rollValue;
updateLabel("Computer's Turn Score: " + comp_turn_score);
return;
}
else //computer roll a 1
{
//reset turn score to 0 and give control to user
comp_turn_score = 0;
updateLabel("\nComputer rolled a 1! Your's Turn");
rollb.setEnabled(true);
}
}
//computer holds
comp_overall_score+= comp_turn_score;
updateLabel("\nComputer Holds! Your's Turn");
if(checkWinner()) return;
rollb.setEnabled(true);
}
private void updateLabel(String s)
{
lable.setText("\nYour score: " + user_overall_score + " Computer Score: " + comp_overall_score +" " + s);
}
if(rollValue != 1)
{
comp_turn_score += rollValue;
updateLabel("Computer's Turn Score: " + comp_turn_score);
return;
}
删除返回语句,一切都会按计划进行。
我是一名优秀的程序员,十分优秀!