#ifndef BOARD_H
#define BOARD_H
//#include "TicTacToe.hpp"
//#include <iostream>
//using namespace std;
enum State {Win, Draw, Continue};
class Board
{
private:
//declare the array for our board with 3 rows and 3 columns
char playBoard[3][3];
public:
Board();
bool makeMove(int, int, char);
State gameState();
void print();
};
#endif
In the board.cpp file you don't need to include the TicTacToe header file.
In the gameState function, line can win if it is all the '.' character.
State Board::gameState()
{
{
if ((playBoard[0][0] == playBoard[0][1]) &&
(playBoard[0][1] == playBoard[0][2]))
return Win;
In the TicTacToe header file, you don't need the iostream header or std namespace.
#ifndef TICTACTOE_H
#define TICTACTOE_H
#include "Board.hpp"
// #include <iostream>
// using namespace std;
class TicTacToe
{
private:
Board newPlay;
char player1;
public:
TicTacToe(char);
void play();
};
#endif
In TicTacToe.cpp you don't need to include Board.hpp, as it is included in the TicTacToe header file.
In the play function the setting of player2 is required only once, so does not need to be in the loop.
if (player1 == 'x')
{
player2 = 'o';
}
else //if (player1 == 'o')
{
player2 = 'x';
}
After player1 makes a move you call gameState but do not check the returned value.
You print the board before player1 moves, and before player2 moves and after player2 moves.

New Topic/Question
Reply




MultiQuote


|