0
안녕하세요, 저는 플레이어가 PC와 경기를하는 과장된 발가락 게임을하려고합니다. 유일한 문제는 플레이어 나 PC의 이동을 검증 할 수 없다는 것입니다. PC가 보드에 이동을 놓으면 플레이어가 점유 할 점이없는 동일한 위치에 이동을 배치 할 수 없습니다. 같은 PC로갑니다. . 내 코드가 아래에 있으므로 그것을 살펴보고이를 수정하는 방법을 알려주십시오.tic tac toe에서 플레이어 입력을 확인하는 방법은 무엇입니까?
for(row=0;row<3;row++){
for(col=0;col<3;col++){
board[row][col]=' ';
}
}
cout << endl << endl;
for(row=0;row<3;row++){
for(col=0;col<3;col++){
cout << "|" << board[row][col] << "|" ;
}
cout << endl << "|-||-||-|" ;
cout << endl;
}
cout << endl << endl << endl;
cout << "Are you player 1 or 2?: ";
cin >> player;
cout << endl << endl << endl;
if(player==1){
cout << "Your symbol is 'O'.The computer's is 'X' " << endl;
}else if(player==2){
cout << "Your symbol is 'X'.The computer's is 'O' " << endl;
}
cout << endl << endl;
while(Gameover==false){
while(win==false){
if(player==1){
cout << "Enter row: ";
cin >> r;
cout << "Enter column: ";
cin >> c;
srand(time(0));
x=rand()%3;
y=rand()%3;
cout << endl << endl << endl;
if(board[row][col]!=' '){
cout << "Invalid move.That spot is already occupied.";
cout << endl << endl << endl;
cout << "Enter row: ";
cin >> r;
cout << "Enter column: ";
cin >> c;
srand(time(0));
x=rand()%3;
y=rand()%3;
}
board[r][c]='O';
board[x][y]='X';
}else if(player==2){
cout << "Enter row: ";
cin >> r;
cout << "Enter column: ";
cin >> c;
srand(time(0));
x=rand()%3;
y=rand()%3;
if(board[row][col]!=' '){
cout << "Invalid move.That spot is already occupied.";
cout << endl << endl << endl;
cout << "Enter row: ";
cin >> r;
cout << "Enter column: ";
cin >> c;
srand(time(0));
x=rand()%3;
y=rand()%3;
}
board[r][c]='X';
board[x][y]='O';
}
cout << endl << endl << endl;
for(row=0;row<3;row++){
for(col=0;col<3;col++){
cout << "|" << board[row][col] << "|" ;
}
cout << endl << "|-||-||-|" ;
cout << endl;
}
cout << endl << endl << endl;
}
}
return 0; }
ok 고맙겠습니다.하지만 이제는 다른 문제가 있습니다. 게임의 승자를 결정할 수 없습니다. – nz881
가능한 모든 방법을 테스트 할 수 있으며 8 가지 방법이 있습니다. winner end game이있는 경우 8 case switch 문을 사용합니다. 플레이어가 X 또는 O이면 게임의 구걸에서 승자를 결정하려면 배열의 내용을 결정할 수 있습니다. –