#include <stdio.h>
#include <stdlib.h>
char matrix[3][3];
char check();
void init_matrix();
void get_first_player_move();
void get_second_player_move();
void disp_matrix();
int main()
{
char done;
std::cout<<"Game START!\n"<<std::endl;
done=' ';
init_matrix();
do{
disp_matrix();
get_first_player_move();
done=check();
if(done!=' ') break;
get_second_player_move();
done=check();
}while(done==' ');
if(done='X')
std::cout<<"The first player WIN!!!\n";
else
std::cout<<"The second player WIN!!!\n";
disp_matrix();
return 0;
}
void init_matrix()
{
init i,j;
for(i=0;i<3++i)
for(j=0;j<3++j) matrix[j]=' ';
}
void get_first_player_move()
{
int x,y;
std::cout<<"Input you coordinate: x and y\n";
std::cin>>x>>y;
x--;
y--;
if(matrix[x][y]!=' ')
{
std::cout<<"Wrong!Please,try again!\n";
get_first_player_move();
}
else matrix[x][y]='X';
}
void get_second_player_move()
{
int x,y;
std::cout<<"Input you coordinate: x and y\n";
std::cin>>x>>y;
x--;
y--;
if(matrix[x][y]!=' ')
{
std::cout<<"Wrong!Please,try again!\n";
get_second_player_move();
}
else matrix[x][y]='O';
}
void disp_matrix()
{
int i;
for(i=0;i<3;++i)
{
std::cout<<matrix[0]<<" | "<<matrix[1]<<" | "<<matrix[2];
if(i!=2)std::cout<<"\n ---|---|---";
}
std::endl;
char check();
{
int i;
for(i=0;i<3;++i)
if(matrix[0]==matrix[1]&&
matrix[0]==matrix[2])return matrix[0];
for(i=0;i<3;++i)
if(matrix[0]==matrix[1]&&
matrix[0]==matrix[2])return matrix[0];
if(matrix[0][0]==matrix[1][1]&&
matrix[1][1]==matrix[2][2])return matrix[0][0];
if(matrix[0][2]==matrix[1][1]&&
matrix[1][1]==matrix[2][0])return matrix[0][2];
return ' ';
}
КРЕСТИКИ-НОЛИКИ(С++)
:confused:
Лови!