C++ C++;井字游戏
可能重复:C++ C++;井字游戏,c++,visual-c++,tic-tac-toe,C++,Visual C++,Tic Tac Toe,可能重复: 我尽了最大的努力,这就是我到目前为止所做的,请帮助我。这是我需要完成的代码 实现显示板以显示Tic Tac趾板 提示用户在板上选择一个框,即1到9之间的数字,1为左上角 使用cin.get(box)获取框号,并使用isdigit验证它是否为 数量; 1 | 2 | 3 4 | 5 | 6 7 | 8 | 9 如果盒子可用,将适当的X或O放入其中并切换播放器,即X变为O,反之亦然。 如果该框不可用,则警告用户并获取另一个框,直到用户选择有效的打开框 在所有点都被选中后,显示“游戏结束
我尽了最大的努力,这就是我到目前为止所做的,请帮助我。这是我需要完成的代码
#include <iostream>
using namespace std;
class TicTacToe {
public:
void displayBoard();
void getMove();
void playGame();
private:
char board[9];
char player; // Switch after each move.
};
int main ()
{
TicTacToe ttt;
// you need to do the following in a loop 9 times
ttt.playGame();
}
void TicTacToe::playGame()
{
getMove();
// Your implementation here...
}
void TicTacToe::displayBoard()
{
// Your implementation here...
}
void TicTacToe::getMove()
{
cout << "Enter Box: ";
char c;
cin.get(c);
if (c > '9' || c < '0')
// Error message here.
int number = c - '0';
cout << "your number is " << number;
// Your implementation here...
}
#包括
使用名称空间std;
提克塔克类{
公众:
无效显示板();
void getMove();
无效游戏();
私人:
炭板[9];
char player;//每次移动后切换。
};
int main()
{
蒂克塔克托ttt;
//您需要在循环中执行以下操作9次
ttt.playGame();
}
void TicTacToe::playGame()
{
getMove();
//您在这里的实现。。。
}
void TicTacToe::displayBoard()
{
//您在这里的实现。。。
}
void TicTacToe::getMove()
{
cout'9'| c<'0')
//此处显示错误消息。
整数=c-‘0’;
我可以假设这是一个作业或家庭作业问题吗
请注意,它要求您填写一些空方法的实现。因此,您需要在第一个清单的框架中编写代码。还要注意,该清单中的TictaToe类使用字符数组定义了board
例如:
void TicTacToe::displayBoard(){
std::cout << board[1] << "|" << board[2]<< "|" << board[3]<< std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << board[4] << "|" << board[5]<< "|" << board[6]<< std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << board[7] << "|" << board[8]<< "|" << board[9]<< std::endl;
}
void TicTacToe::displayBoard(){
std::请不要重复问题,它唯一的作用是让问题结束。再次问同样的问题没有帮助。最好修复旧问题。
void TicTacToe::displayBoard(){
std::cout << board[1] << "|" << board[2]<< "|" << board[3]<< std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << board[4] << "|" << board[5]<< "|" << board[6]<< std::endl;
std::cout << "-+-+-"<< std::endl;
std::cout << board[7] << "|" << board[8]<< "|" << board[9]<< std::endl;
}