#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
char matrix[3][3];
void cou(void);
void cou(void)
{
printf("\n\t\t 1 2 3 \n\n");
printf("\t\t 1 %c | %c | %c \n",matrix[0][0],matrix[0][1],matrix[0][2]);
printf("\t\t ---|---|---\n");
printf("\t\t 2 %c | %c | %c \n",matrix[1][0],matrix[1][1],matrix[1][2]);
printf("\t\t ---|---|---\n");
printf("\t\t 3 %c | %c | %c \n",matrix[2][0],matrix[2][1],matrix[2][2]);
}
void main()
{
int m,n;
int i,j,sum=0;
char ch='y';
while(ch=='Y' || ch=='y')
{
for(m=0;m<3;m++)
for(n=0;n<3;n++)
matrix[m][n]='\0';
while(sum<10)
{
if(sum==0)
cou();
printf(" Player1 is 'X' : choose the row and column \n");
printf(" Row : ");
scanf("%d",&i);
printf(" Column :L ");
scanf("%d",&j);
for(;i>3||i<1||j>3||j<1||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
printf(" Sorry but you gotta choose another place .\n");
printf(" ROW :");
scanf("%d",&i);
printf(" COLUMN : ");
scanf("%d",&j);
}
matrix[i-1][j-1]='X';
sum++;
cou(); // calling function to display game setup
//check if player 1 wins
if(matrix[0][0]=='X' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][2]=='X' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='X' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[1][0]=='X' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='X' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(sum==9) // because there are only 9 boxes
{
printf(" The game is over and no one wins , haha lols \n");
break;
}
//player 2 's turn
printf(" Pkayer2 is 'O' : choose the row and column \n");
printf(" Row ");
scanf("%d",&i);
printf(" Column : ");
scanf("%d",&j);
for(;i>3||i<1||j>3||j<1||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
printf(" Sorry but you gotta choose another place .\n");
printf(" ROW :");
scanf("%d",&i);
printf(" COLUMN : ");
scanf("%d",&j);
}
matrix[i-1][j-1]='O';
sum++;
cou(); // calling function to display game setup
//check if player 1 wins
if(matrix[0][0]=='O' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='O' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='O' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][1]=='O' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][2]=='O' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='O' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
printf(" \n Would you like to play again ??? (Y-N)\n");
scanf("%c",&ch);
}
system("PAUSE");
}
}
#include<stdio.h>
#include<stdlib.h>
char matrix[3][3];
void cou(void);
void cou(void)
{
printf("\n\t\t 1 2 3 \n\n");
printf("\t\t 1 %c | %c | %c \n",matrix[0][0],matrix[0][1],matrix[0][2]);
printf("\t\t ---|---|---\n");
printf("\t\t 2 %c | %c | %c \n",matrix[1][0],matrix[1][1],matrix[1][2]);
printf("\t\t ---|---|---\n");
printf("\t\t 3 %c | %c | %c \n",matrix[2][0],matrix[2][1],matrix[2][2]);
}
void main()
{
int m,n;
int i,j,sum=0;
char ch='y';
while(ch=='Y' || ch=='y')
{
for(m=0;m<3;m++)
for(n=0;n<3;n++)
matrix[m][n]='\0';
while(sum<10)
{
if(sum==0)
cou();
printf(" Player1 is 'X' : choose the row and column \n");
printf(" Row : ");
scanf("%d",&i);
printf(" Column :L ");
scanf("%d",&j);
for(;i>3||i<1||j>3||j<1||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
printf(" Sorry but you gotta choose another place .\n");
printf(" ROW :");
scanf("%d",&i);
printf(" COLUMN : ");
scanf("%d",&j);
}
matrix[i-1][j-1]='X';
sum++;
cou(); // calling function to display game setup
//check if player 1 wins
if(matrix[0][0]=='X' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='X' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='X' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][1]=='X' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][2]=='X' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='X' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[1][0]=='X' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='X' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(sum==9) // because there are only 9 boxes
{
printf(" The game is over and no one wins , haha lols \n");
break;
}
//player 2 's turn
printf(" Pkayer2 is 'O' : choose the row and column \n");
printf(" Row ");
scanf("%d",&i);
printf(" Column : ");
scanf("%d",&j);
for(;i>3||i<1||j>3||j<1||('X'==matrix[i-1][j-1]||'O'==matrix[i-1][j-1]);)
{
printf(" Sorry but you gotta choose another place .\n");
printf(" ROW :");
scanf("%d",&i);
printf(" COLUMN : ");
scanf("%d",&j);
}
matrix[i-1][j-1]='O';
sum++;
cou(); // calling function to display game setup
//check if player 1 wins
if(matrix[0][0]=='O' && matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='O' && matrix[2][0]==matrix[1][1] && matrix[1][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='O' && matrix[0][0]==matrix[1][0] && matrix[1][0]==matrix[2][0])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][1]=='O' && matrix[0][1]==matrix[1][1] && matrix[1][1]==matrix[2][1])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][2]=='O' && matrix[0][2]==matrix[1][2] && matrix[1][2]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[0][0]=='O' && matrix[0][0]==matrix[0][1] && matrix[0][1]==matrix[0][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[1][0]=='O' && matrix[1][0]==matrix[1][1] && matrix[1][1]==matrix[1][2])
{
printf(" Player 1 wins \n");
break;
}
if(matrix[2][0]=='O' && matrix[2][0]==matrix[2][1] && matrix[2][1]==matrix[2][2])
{
printf(" Player 1 wins \n");
break;
}
printf(" \n Would you like to play again ??? (Y-N)\n");
scanf("%c",&ch);
}
system("PAUSE");
}
}
No comments:
Post a Comment