想编一个一条龙(井字棋)的小游戏,但不知如何比较胜负。
下面的是我初步编的代码,要想在游戏中决出胜负的话,就要在bool中把胜负写成三种类型。(横,竖,斜)但本人实在不太清楚要如何写出这3个部分并把他们加到main中并提示结果。还请各位大师指点一二了。
#include <iostream>,
using namespace std;
bool checkWin(char symbol, char board[3][3])
{
}
void displayGrid(char game[3][3])
{
cout << game[0][0] << '|' << game[0][1] << '|' << game[0][2] << endl;
cout << "-+-+-" << endl;
cout << game[1][0] << '|' << game[1][1] << '|' << game[1][2] << endl;
cout << "-+-+-" << endl;
cout << game[2][0] << '|' << game[2][1] << '|' << game[2][2] << endl;
}
int main()
{
char gameGrid[3][3] = {{'X','O','O '},
{' ','X','X'},
{'X','O','X '}};
char player1 = 'X';
char player2 = 'O';
cout << "The position is: " << endl;
displayGrid(gameGrid);
return 0;
}