我在这里正确传递参数了吗?

Am I passing parameters on properly here?

本文关键字:参数 在这里      更新时间:2023-10-16

我正在为课堂制作一个超级简单的井字游戏。为了确定是否在数组的一部分上放置"X"或"O",我建立了一个名为"turn"的整数来确定当前 2 个玩家中的哪一个在玩。

int main()
{
bool win, tie = false;
int input;
char theBoard[LENGTH] = {SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE, SPACE};
int turn = 1;
showInstructions();
do
{
showBoard(theBoard);
getMove(turn, input, theBoard);
if (turn == 1)
{
turn++;
}
else if (turn == 2)
{
turn--;
}
}
while(win == false || tie == false);
return 0;

这是我的getMove函数。

void getMove(int input, int turn, char theBoard[LENGTH])
{
cout << "Pick a space from 0 - 8" << endl;
cin >> input;
if (input >= 0 && input <= 8)
{
if (turn == 1)
{
theBoard[input] = X;
}
else if (turn == 2)
{
theBoard[input] = O;
}
}
else
{
cout << "Please make a valid move between 0 - 8" << endl;
cin.ignore();
cin.get();
}
}

您可能需要检查您的getMove声明。你用turn, input, theBoardmain称呼它,但它期望input, turn, theBoard

相关文章: