私は現在、大学向けのゼロとクロスのプログラムを作成しています。この任務の必要最小限の作業は完了しましたが、ゲームを終了するための勝利条件を作成するのに問題があります。以下は、これまでに使用したすべてのコードです。
#include <iostream>
#include <string>
using namespace std;
class Player
{
private:
char NorX;
public:
char Choose(char InitialValue)
{
NorX = InitialValue;
return InitialValue;
}
char GetNorX()
{
return NorX;
}
};
int main()
{
Player Player1;
Player Player2;
Player1.Choose('O');
Player2.Choose('X');
cout << "The board is being drawn please wait..." << endl;
const int Rows = 4;
const int Columns = 4;
char Board[Rows][Columns] = { {' ', ' ', ' ', ' ' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' },
{' ', '_', '_', '_' } };
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
cout << endl << endl;
int row;
int column;
do
{
do
{
cout << "Please enter the value of the row you would like to take ";
cin >> row;
}while (row != 0 && row != 1 && row != 2 && row != 3);
do
{
cout << "Please enter the value of the column you would like to take ";
cin >> column;
}while (column != 0 && column != 1 && column != 2 && column != 3);
Board [row][column] = Player1.GetNorX();
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
/*int row;*/
do
{
cout << "Please enter the value of the row you would like to take ";
cin >> row;
}while (row != 0 && row != 1 && row != 2 && row != 3);
/*int column;*/
do
{
cout << "Please enter the value of the column you would like to take ";
cin >> column;
}while (column != 0 && column != 1 && column != 2 && column != 3);
Board [row][column] = Player2.GetNorX();
for (int i = 0; i < Rows; ++i)
{
for (int j = 0; j < Columns; ++j)
cout << Board [i][j];
cout << endl;
}
if (Board[1][1] == Board[1][2] == Board[1][3] == 'O')
{
cout << endl << "Well done you win";
}
}while (column != 4 && row != 4);
system("pause");
}
プログラムの実行に影響を与えていないように見えるため、問題は if ステートメントで発生します。