this is a program about (x,o) game .. i have been trying to deal with it for 3 houres and untill now i did not finished it
This is my try about it and i wish any one can help me finishing it pleeeeeeeeeeeeeeeeeeeeeez
**the program should check each time if any one of the 2 players win or not
** i am working on visual c++ please try 2 help me
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
#include<windows.h>
void gotoxy(int x,int y);
bool check(char ch,char arr[][3]);
void main()
{
int i,j,a;
char ch,arr[3][3];
cout<<" ______________\n"
<<"|0,0 |0,1 |0,2 |\n"
<<"| | | |\n"
<<"|--------------|\n"
<<"|1,0 |1,1 |1,2 |\n"
<<"| | | |\n"
<<"|--------------|\n"
<<"|2,0 |2,1 |2,2 |\n"
<<"| | | |\n"
<<" -------------- \n";
for (int x=1;x<10;x++)
{
if (x%2==0)
{
cout<<"Player 2 :";
cout<<"please enter ur character( x or y ) :";
cin>>ch;
cout<<"please enter the place u want to put ur character in : ";
cin>>i;
cin>>j;
gotoxy(i+30,j+30);
cout<<ch;
a=check(ch,arr);
if (a==1)
cout<<"PLAYER 2 WIN";
}
else
{
cout<<"Player 1 :";
cout<<"please enter ur character( x or y ) :";
cin>>ch;
cout<<"please enter the place u want to put ur character in : ";
cin>>i;
cin>>j;
gotoxy(i+30,j+30);
cout<<ch;
a=check(ch,arr);
if (a==1)
cout<<"PLAYER 1 WIN";
}
}
cout<<"GAME OVER";
getch();
}
//**************************************************************
bool check(char ch,char arr[][3])
{
for (int i=0;i<3;i++)
{
for (int j=0;j<3;j++)
{
if (ch!=arr[j])
break;
}
if (j==3)
return true;
}
return false;
// end of checking rows.
for (int j=0;j<3;j++)
{
for (int i=0;i<3;i++)
{
if (ch!=arr[j])
break;
}
if (i==3)
return true;
}
return false;
// end of checking colums.
for (int x=0;x<3;x++)
{
for (int j=x;j<x+1;j++)
{
if (ch!=arr[x][j])
break;
}
if (j==3)
return true;
}
return false;
// end of checking the first diameter.
for (int y=0,k=2;y<3;y++,k--)
{
if (ch!=arr[y][k])
break;
if (y==3)
return true;
}
return false;
// end of checking the second diameter.
}
//********************************************************
void gotoxy(int x,int y)
{
COORD coor;
HANDLE hOutput;
hOutput=GetStdHandle(STD_OUTPUT_HANDLE);
coor.X=x;
coor.Y=y;
SetConsoleCursorPosition(hOutput,coor);
}i know it is wrong but this what i can make ..... try 2 make run for it and help me pleez by telling me where is the mistakes
and thanx alooooot 4 every one gonna read it and try to help me
