Public Member Functions | Protected Types | Protected Attributes | Static Protected Attributes

Grid Class Reference

The grid. More...

#include <Grid.h>

List of all members.

Public Member Functions

 Grid (CIwFVec2 position, int tileSize)
 ~Grid ()
void Draw ()
int GetNumberOfColliders ()
int GetNumberOfColumns ()
PhysicsObjectGetTopCollider (int index)
RectangleColliderGetColumnSideCollider (int index)
PhysicsObjectGetColumnTopCollider (int index)
float GetPositionOfNextEmptySquareInColumn (int index)
int GetIndexOfNextEmptySquareInColumn (int index)
void DecreaseEmptySquaresInColumn (int index)
void SetColumnSquare (int column, int row, int colour)
void PreventColumnOverflow (int index)
bool IsColumnFull (int index)
int CheckForWinner ()
void ClearGrid ()
void ToCharArray (char(&arr)[6][7])

Protected Types

enum  Result { REDWIN = 1, YELLOWWIN = 2, DRAW = 3 }
 

Possible match results.


Protected Attributes

CIwFVec2 m_position
 Position of the grid (top left corner).
GridColumnm_columns [m_numColumns]
 Array of grid columns.
PhysicsObjectm_colliders [m_numColliders]
 Array of colliders.
RectangleColliderm_columnSideColliders [m_numSideColliders]
 Array of column side colliders.
PhysicsObjectm_columnTopColliders [m_numTopColliders]
 Array of column top colliders. Used for collisions when the column is full.
float m_colliderRadius
 Radius of the colliders.
float m_colliderMass
 Mass of the colliders. Used in collision solving.
float m_sideColWidth
 Width of a column side collider.
float m_sideColHeight
 Height of a column side collider.
float m_topColliderRadius
 Radius of a top collider.

Static Protected Attributes

static const int m_numColumns = 7
 Number of columns.
static const int m_numRows = 6
 Number of rows.
static const int m_numColliders = 8
 Number of colliders at top of columns.
static const int m_numSideColliders = 8
 Number of colliders between columns.
static const int m_numTopColliders = 7
 Number of colliders at top of columns which will prevent discs from entering full columns.

Detailed Description

The grid.

Grid and associated physics objects.


Constructor & Destructor Documentation

Grid::Grid ( CIwFVec2  position,
int  tileSize 
)

Constructor.

Create a new grid.

Parameters:
[in] position Position of the grid (top left corner).
[in] tileSize Size of a grid tile.
Grid::~Grid (  ) 

Destructor.

Destroy the grid and release all associated memory.


Member Function Documentation

int Grid::CheckForWinner (  ) 

Check if someone has won.

Iterates through the grid and checks for four discs of the same colour in a row.

Returns:
int representing the colour of the winner (if any).
void Grid::ClearGrid (  ) 

Clear grid.

Resets the grid. Removes all discs from it.

void Grid::DecreaseEmptySquaresInColumn ( int  index  ) 

Mark a square as full.

Marks the next empty square in specific column as full/occupied.

Parameters:
[in] index Index of the column.
void Grid::Draw (  ) 

Draw.

Draws the grid.

RectangleCollider * Grid::GetColumnSideCollider ( int  index  ) 

Get side collider.

Get a specific collider from the side of a grid column.

Parameters:
[in] index Index of the collider to be returned.
Returns:
PhysicsObject* The collider.
PhysicsObject * Grid::GetColumnTopCollider ( int  index  ) 

Get column top collider.

Get a specific collider from the top of a column.

Parameters:
[in] index Index of the collider to be returned.
Returns:
PhysicsObject* The collider.
int Grid::GetIndexOfNextEmptySquareInColumn ( int  index  ) 

Get next empty square index.

Returns the index of the next empty square in a specific column.

Parameters:
[in] index Index of the column.
Returns:
int Index of the square.
int Grid::GetNumberOfColliders (  ) 

Get total colliders.

Get the number of colliders along the top of the grid.

Returns:
int number of colliders.
int Grid::GetNumberOfColumns (  ) 

Get total columns.

Get the number of columns in the grid.

Returns:
int number of columns.
float Grid::GetPositionOfNextEmptySquareInColumn ( int  index  ) 

Get next empty square position.

Returns the position of the next empty square in a specific column.

Parameters:
[in] index Index of the column.
Returns:
float Position of the square.
PhysicsObject * Grid::GetTopCollider ( int  index  ) 

Get top collider.

Get a specific collider from the top of the grid.

Parameters:
[in] index Index of the collider to be returned.
Returns:
PhysicsObject* The collider.
bool Grid::IsColumnFull ( int  index  ) 

Is column full?

Check whether a specific column is full.

Parameters:
[in] index Index of the column.
Returns:
bool representing whether column is full.
void Grid::PreventColumnOverflow ( int  index  ) 

Prevent overflow.

Prevent a disc from being placed into a full column.

Parameters:
[in] index Index of the column.
void Grid::SetColumnSquare ( int  column,
int  row,
int  colour 
)

Set column square colour.

Set the state of a column square (red, yellow, empty).

Parameters:
[in] column Index of the column.
[in] row Index of the row.
[in] colour Colour to set it to.
void Grid::ToCharArray ( char(&)  arr[6][7]  ) 

To char array.

Convert the grid to a character array (for faster ai game tree searching). E = empty tile. R = red tile. Y = yellow tile.

Parameters:
[out] arr An empty array which the grid array be written to.

The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations