Project 3: Connect 4  Version 4
1-2-3-4 in a row
 All Classes Functions Variables
Public Member Functions | Private Member Functions | Private Attributes | List of all members
Board Class Reference

#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
 

Detailed Description

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.

Constructor & Destructor Documentation

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.

Member Function Documentation

bool Board::checkCol ( int  col)
private

Same as for checkRow and checkDiag, I use this in checking for wins.

bool Board::checkDiag ( int  dia)
private

This is the same as the checkRow and checkCol methods. I use this for checking for wins.

bool Board::checkRow ( int  row)
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.

Parameters
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.

Returns
True if the game is in draw state and false otherwise
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.

Parameters
checker- the Checker to be dropped
column- an int that represents the column to be dropped into
Returns
True if the Checker could be dropped into the column and false otherwise.
bool Board::gameOver ( )

This will return true if the game is in a win or draw state

Returns
True if the game is in a win or draw state and false otherwise
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.

Returns
True is a winning condition is found and false otherwise.

Member Data Documentation

string Board::board[rows][cols]
private

This is the main game board. It needs to be 2 dimensional

int Board::checkerCount
private

I use this to keep track of how many checkers have been placed. I use this for checking draws.


The documentation for this class was generated from the following files: