4 개의 행을 조인하는 것이 목표 인이 게임을 만드는 데 문제가 있습니다. 현재,이 프로그램은 처음에 while
조건에 도달하면 종료됩니다. 그러나 나에게 맞지 않더라도 Do While 루프를 다시 수행해야합니다. 아직 게임이 끝나지 않았 음을 유의하십시오.Do While 루프가 올바르게 종료되지 않습니다.
int main()
{
cout << "\t \t \t Welcome to Four In A Row" << endl << endl;
cout << "Player 1: Please enter your name: ";
cin >> player1name;
cout << endl;
cout << "Player 2: Please enter your name: ";
cin >> player2name;
do
{
cout << player1name << " please enter point" << endl;
cin >> p1x >> p1y;
cout << endl;
player1.setpoint(p1x, p1y); cout << endl;
point[p1x][p1y] = 'x';
wincheck(p1x, p1y);
cout << player2name << " please enter point" << endl;
cin >> p2x >> p2y;
cout << endl;
player2.setpoint2(p2x, p2y); cout << endl;
point[p1x][p1y] = 'o';
wincheck(p2x, p2y);
if(wincheck != false) loopexit = 1;
}while(loopexit == 0);
return 0;
}
bool wincheck(int, int)
{
int vertical = 1;
int horizontal = 1;
int diagonal1 = 1;
int diagonal2 = 1;
char player = point[p1x][p1y];
int verticalcheck;
int horizontalcheck;
for(verticalcheck = p1x + 1; point[verticalcheck][p1y] == player && verticalcheck <= 5; verticalcheck++, vertical++);
for(verticalcheck = p1y - 1; point[verticalcheck][p1y] == player && verticalcheck >= 0; verticalcheck--, vertical++);
if(vertical >= 4) return true;
for(horizontalcheck = p1y -1; point[p1x][horizontalcheck] == player && horizontalcheck >= 0; horizontalcheck--, horizontal++);
for(horizontalcheck = p1y +1; point[p1x][horizontalcheck] == player && horizontalcheck <= 6; horizontalcheck++, horizontal++);
if(horizontal>= 4) return true;
for(verticalcheck = p1x -1, horizontalcheck = p1y -1; point[verticalcheck][horizontalcheck] == player && verticalcheck >= 0 && horizontalcheck >=0; diagonal1++, verticalcheck--, horizontalcheck--);
for(verticalcheck = p1x +1, horizontalcheck = p1y +1; point[verticalcheck][horizontalcheck] == player && verticalcheck <= 5 && horizontalcheck <=6; diagonal1++, verticalcheck++, horizontalcheck++);
if(diagonal1 >= 4) return true;
for(verticalcheck = p1x -1, horizontalcheck = p1y +1; point[verticalcheck][horizontalcheck] == player && verticalcheck >= 0 && horizontalcheck <= 6; diagonal2++, verticalcheck--, horizontalcheck++);
for(verticalcheck = p1x +1, horizontalcheck = p1y -1; point[verticalcheck][horizontalcheck] == player && verticalcheck <= 5 && horizontalcheck >=0 ; diagonal2++, verticalcheck++, horizontalcheck--);
if(diagonal2 >= 4) return true;
else return false;
변수 loopexit의 초기 값은 무엇입니까? while 조건은 loopexit이 0인지 확인하지만 게시 한 코드의 어느 곳에서도 0으로 설정하지 않습니다. –
메인 외부에서 0으로 설정되었습니다. 나머지 코드는 불필요하다고 생각했습니다. – user3380905