TicTacToe.h
Code:
#ifndef _TICTACTOE_
#define _TICTACTOE_
#define ROWCOLTOMEM (row,col) ((row)*(3)+(col))
#define FAILURE 1
#define SUCCESS 0
#define EMPTY 0
#define FULL 1
#define XPIECE 1
#define YPIECE 2
class TicTacToe
{
protected:
unsigned char *Board;
int numslotsfree;
public:
TicTacToe(void);
~TicTacToe(void);
int Init(void);
unsigned char GetBoardValue(int row,int col);
int SetBoardValue(int row,int col);
//You figure these out
int CheckForWin(void)=0;
void SaveToDisk(void)=0;
void LoadFromDisk(void)=0;
};
#endif
TicTacToe.cpp
Code:
#include "TicTacToe.h"
TicTacToe::TicTacToe(void)
{
Board=0;
numslotsfree=0;
}
TicTacToe::~TicTacToe(void)
{
if (Board) delete [] Board;
}
int TicTacToe::Init(void)
{
numslotsfree=9;
Board=new unsigned char[9];
if (!Board) return FAILURE
else return SUCCESS;
}
unsigned char TicTacToe::GetBoardValue(int row,int col)
{
return Board[ROWCOLTOMEM(row,col)];
}
int TicTacToe::SetBoardValue(int row,int col,int value)
{
Board[ROWCOLTOMEM(row,col)]=value;
}
Player.h
Code:
#ifndef _PLAYER_
#define _PLAYER_
#include "TicTacToe.h"
class Player
{
protected:
unsigned char *name;
int piecevalue;
public:
Player(void);
~Player(void) {};
void Init(unsigned char *_name,int _piecevalue);
int Move(TicTacToe *_gameptr,int row,int col);
};
#endif
Player.cpp
Code:
#include "Player.h"
Player::Player(void)
{
name=0;
piecevalue=0;
}
void Player::Init(unsigned char * _name,int _piecevalue)
{
name=_name;
piecevalue=_piecevalue;
}
int Player::Move(TicTacToe *_gameptr,int row,int col)
{
int testvalue=gameptr->GetBoardValue(row,col);
if (testvalue==EMPTY)
{
gameptr->SetBoardValue(row,col,piecevalue);
return(SUCCESS);
} else return(FULL);
}
That is a very good start for you.