中没有效果我做了一个很好的井字游戏。最近我决定添加重置游戏功能。 这里就是我需要来自用户的输入现在程序在调试中正常工作,但在版本
void playerMove() //Gets the player move and updates the box variables
{
int boxnumber;
while(1) //Set's loop if the player enters a invalid input
{
cout << "\n Player " << player << "'s turn!(Press 0 to reset the game!): ";
cin >> boxnumber;
if(box[boxnumber-1] == 'X' || box[boxnumber-1] == 'O' || boxnumber > 9 || boxnumber < 0) // Checks if the input is valid or not
{
system("CLS");//If invalid, show error and loop back to start to get new input
displayBoard();
cout << "\n Invalid Input! Try again!\n";
}else if(boxnumber == 0)
{
refreshGame();
displayBoard();
}else
{
box[boxnumber-1] = player;//If inputs are fine, set the box variable's and break out of loop!
break;
}
}
}
,在调试模式下的一部分,当我按0,一切都正常运行,游戏复位,但在发布版本中,当我按0,它给我是“输入无效!再试一次!”
我试过的东西没有工作: - 重建整个版本和调试版本。 - 制作一个新项目并复制粘贴我的代码。同样的事情,调试工作,发布没有。
对于任何人想知道的,我使用code :: blocks IDE。编译器是GNU GCC。 感谢您的帮助! :)
我不认为你可以得到箱[-1] –
什么是'boxnumber-1'去当你输入'0'时,是否在'box [boxnumber-1]'中? – NathanOliver