This little game almost works good , but i dont know how to make it visually better and another problem is my program doesn't show who wins, the game never ends:/
Hope for your help
This is my code so far:
Code:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
bool rez(char koord[3][3])
{
for(int i=0;i<3;i++)
{
if (koord[i][0]==koord[i][1] && koord[i][1]==koord[i][2] && (koord[i][0]=='X' || koord[i][0]=='O')) return true;
else return false;
if (koord[0][i]==koord[1][i] && koord[1][i]==koord[2][i] && (koord[i][0]=='X' || koord[i][0]=='O')) return true;
else return false;
if (koord[0][0]==koord[1][1] && koord[1][1]==koord[2][2] && (koord[1][1]=='X' || koord[1][1]=='O')) return true;
else return false;
}
}
void print (char koord[3][3])
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<koord[i][j];
}
cout<<endl;
}
}
int main()
{
char koord[3][3]={{0,0}};
char simb,user,pc;
int rin,kon,pcrin,pckon;
srand(time(NULL));
cout<<"Please choose the simbol - X vai O!"<<endl;
cin>>simb;
if (simb=='O')
{
user='O';
pc='X';
}
else
{
user='X';
pc='O';
}
do
{
cout<<"Choose the row and column!"<<endl;
cin>>rin;
cin>>kon;
kon--;
rin--;
if ((rin>=3 || rin<0) || (kon>=3 || kon<0)) cout<<"You made a mistake when entered row/column!\n";
pcrin=rand()%3;
pckon=rand()%3;
if (koord[rin][kon]!=pc) koord[rin][kon]=user;
if (koord[pcrin][pckon]!=user) koord[pcrin][pckon]=pc;
print(koord);
if (rez(koord)==true)
{
cout<<"Game over!";
break;
}
}
while(koord[3][3]!='X');
return 0;
}