#include <Board.h>
Public Member Functions | |
Board () | |
bool | win () |
bool | draw () |
bool | dropChecker (string checker, int column) |
bool | gameOver () |
void | displayBoard (ostream &out) |
void | resetBoard () |
Private Member Functions | |
bool | checkRow (int) |
bool | checkCol (int col) |
bool | checkDiag (int dia) |
Private Attributes | |
string | board [rows][cols] |
int | checkerCount |
This class represents the game board for our connect 4 game. Our board is 7 columns wide by 6 rows tall. The constants in the file can be used by you for declaring your array and for loop constants etc. The diags const was something I came up with to help me determine a diagonal win. You can use if it is helpful for you, otherwise, feel free to ignore it.
Board::Board | ( | ) |
This is the only constructor for the class. It sets up the array and initializes everything to an empty checker, i.e. one with a "" or " " for name. I can then use this fact of initialization when I go and check for wins.
|
private |
Same as for checkRow and checkDiag, I use this in checking for wins.
|
private |
This is the same as the checkRow and checkCol methods. I use this for checking for wins.
|
private |
This is a private method that I use in checking for wins.
void Board::displayBoard | ( | ostream & | out | ) |
This will display the board. I will give more details on this to come.
out | - the ostream to use when displaying the board. |
bool Board::draw | ( | ) |
This is similar to the win. It checks for a draw. There can only be a draw if all the spaces are filled.
bool Board::dropChecker | ( | string | checker, |
int | column | ||
) |
This drops a checker into the given row. It should check to make sure that the given row is "good". You also need to make sure that the column is currently full of checkers. If so, the drop is returned as false. Good is defined to be between 0 and 6.
checker | - the Checker to be dropped |
column | - an int that represents the column to be dropped into |
bool Board::gameOver | ( | ) |
This will return true if the game is in a win or draw state
void Board::resetBoard | ( | ) |
This will reset the board to all blank checkers and reset the checker count back to 0.
bool Board::win | ( | ) |
This method does what you think. It checks the rows, columns and diagonals for a winning condition. It returns true if it finds one and false otherwise.
|
private |
This is the main game board. It needs to be 2 dimensional
|
private |
I use this to keep track of how many checkers have been placed. I use this for checking draws.