trying to make a tictactoe (in class) c++ program but i cant seem to get the board printed when i enter the 2nd set of numbers.
if you see nay other mistakes please let me know .....
thanks in advance
first time here :)
[//
#include<iostream>
using namespace std;
const int DIM=3;
class TTT
{
public:
void clearboard(int,int);
void chessboard(int, int);
void checker(int, int);
void move(int , int);
void currentboard(int, int);
int row;
int col;
private:
char t3 [DIM][DIM];
};
int main()
{
TTT ttt;
int roww=0,column=0;
ttt.clearboard(roww,column);
ttt.chessboard(roww,column);
ttt.checker(roww,column);
ttt.move(roww,column);
return 0;
}
void TTT::chessboard(int roww,int column)
{
for (int row = 0; row< DIM; row++)
{
for(int col=0; col < DIM; col++)
{
cout <<'|'<<t3[row][col];
}
cout<<'|'<<endl<<"-------"<<endl;
}
}
void TTT::clearboard(int roww, int column)
//set all the elements of the ChessBoard to blanks
{
for (row = 0; row < DIM; row++)
for(col=0; col < DIM; col++)
t3[row][col] = ' ';
}
void TTT::move(int roww, int column)
{
char cur='o';
int putchecker;
int row,col;
cin>>row>>col;
if (row >= 0 && row < DIM && col >= 0 && col < DIM && t3[row][col]==' ')
{
putchecker=true;
t3[row][col]=cur;
}
else putchecker=false;
if(!putchecker)
{
cout<<"Invalid move"<<endl;
}
else
currentboard(roww,column);
}
void TTT::currentboard(int roww, int colum)
{
for (int row = 0; row< DIM; row++)
{
for(int col=0; col < DIM; col++)
{
cout <<'|'<<t3[row][col];
}
cout<<'|'<<endl<<"-------"<<endl;
}
}
void TTT:: checker(int roww, int column)
{
char cur=0;
int chessboard[3][3];
int count1=0,count2=0,count3=0,count4=0;
int row=0, col=0;
int blanks=0;
for(int i=0; i<DIM; i++)
{
if(chessboard[row][i]==cur)
count1++;
if(chessboard[i][col]==cur)
count2++;
if(chessboard[i][i]==cur)
count3++;
if(chessboard[i][DIM-1-i]==cur)
count4++;
}
if(count1 == 3 || count2 == 3 || count3 == 3 || count4 == 3)
{
cout<< cur <<"Wins"<<endl;
return ;
}
/*if(blanks==0)
{
cout<<"Ties"<<endl;
return ;
}*/
if(cur=='X')
cur= 'O';
else cur='X';
{
cout<<"Input position(row col) or(-1 -1) to exit; It is the turn of" <<cur<<endl;
//cin>>row>>col;
}
}
]]