#include <iostream>
#include <string>
using namespace std;
enum SquareState
{
(blank = 's',
X = 'X',
0 ='0')
};
class gameBoard
{
private:
const int WIDTH;
const int HEIGHT;
int* GameBoard;
public:
gameBoard(): WIDTH(3), HEIGHT(3)
{
GameBoard = new int [9];
for (int i = 0; i < 9; i++)
*(GameBoard + i) = blank;
}
~gameBoard() {delete[] GameBoard;}
void setX(int h, int w);
void set0(int h, int w);
bool isTaken(int h, int w);
SquareState isLine();
void draw();
};
void gameBoard::setX(int h, int w)
{
*(GameBoard + h*HEIGHT + w)=X;
}
void gameBoard::set0(int h, int w)
{
*(GameBoard + h*HEIGHT + w)=0;
}
bool gameBoard::isTaken(int h, int w)
{
return *(GameBoard + h*HEIGHT + w)!= '';
}
SquareState gameBoard::isLine()
{
if (*GameBoard==X && *(GameBoard +1)==X && *(GameBoard +2)==X)
return X;
if (*GameBoard==0 && *(GameBoard +1)==0 && *(GameBoard +2)==0)
return 0;
if (*GameBoard +3)==X && *(GameBoard +4)==X && *(GameBoard +5)==X)
return X;
if (*GameBoard +3)==0 && *(GameBoard +4)==0 && *(GameBoard +5)==0)
return 0;
if (*GameBoard +6)==X && *(GameBoard +7)==X && *(GameBoard +8)==X)
return X;
if (*GameBoard +6)==X && *(GameBoard +7)==X && *(GameBoard +8)==X)
return 0;
if (*GameBoard==X && *(GameBoard +4)==X && *(GameBoard +8)==X)
return X;
if (*GameBoard==0 && *(GameBoard +4)==0 && *(GameBoard +8)==0)
return 0;
if (*GameBoard +2)==X && *(GameBoard +4)==X && *(GameBoard +6)==X)
return X;
if (*GameBoard +2)==0 && *(GameBoard +4)==0 && *(GameBoard +6)==0)
return 0;
return blank;
}
void gameBoard::draw()
{
cout<<endl;
for(int i=0; i < HEIGHT; i++)
{
cout << (char)*(GameBoard + i*HEIGHT);
for(int c=1; c < WIDTH; c++)
cout<< " | "<<(char)*(GameBoard + i*WIDTH + c);
cout << endl << "------------"<<endl;
}
}
class Game
{
public:
gameBoard* doInput(string player, gameBoard* gb);
bool inRange(int test);
};
gameBoard* Game::doInput(std::string player, gameBoard *gb)
{
gb->draw();
string letter;
if (player.compare("one")==0)
letter= "X";
else if (player.compare("two")==0)
letter= "0";
else return gb;
int input1, input2;
do{
do{
can u tell me wats the problem