The grid. More...
#include <Grid.h>
Public Member Functions | |
Grid (CIwFVec2 position, int tileSize) | |
~Grid () | |
void | Draw () |
int | GetNumberOfColliders () |
int | GetNumberOfColumns () |
PhysicsObject * | GetTopCollider (int index) |
RectangleCollider * | GetColumnSideCollider (int index) |
PhysicsObject * | GetColumnTopCollider (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). | |
GridColumn * | m_columns [m_numColumns] |
Array of grid columns. | |
PhysicsObject * | m_colliders [m_numColliders] |
Array of colliders. | |
RectangleCollider * | m_columnSideColliders [m_numSideColliders] |
Array of column side colliders. | |
PhysicsObject * | m_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. |
The grid.
Grid and associated physics objects.
Grid::Grid | ( | CIwFVec2 | position, | |
int | tileSize | |||
) |
Constructor.
Create a new grid.
[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.
int Grid::CheckForWinner | ( | ) |
Check if someone has won.
Iterates through the grid and checks for four discs of the same colour in a row.
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.
[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.
[in] | index | Index of the collider to be returned. |
PhysicsObject * Grid::GetColumnTopCollider | ( | int | index | ) |
Get column top collider.
Get a specific collider from the top of a column.
[in] | index | Index of the collider to be returned. |
int Grid::GetIndexOfNextEmptySquareInColumn | ( | int | index | ) |
Get next empty square index.
Returns the index of the next empty square in a specific column.
[in] | index | Index of the column. |
int Grid::GetNumberOfColliders | ( | ) |
Get total colliders.
Get the number of colliders along the top of the grid.
int Grid::GetNumberOfColumns | ( | ) |
Get total columns.
Get the number of columns in the grid.
float Grid::GetPositionOfNextEmptySquareInColumn | ( | int | index | ) |
Get next empty square position.
Returns the position of the next empty square in a specific column.
[in] | index | Index of the column. |
PhysicsObject * Grid::GetTopCollider | ( | int | index | ) |
Get top collider.
Get a specific collider from the top of the grid.
[in] | index | Index of the collider to be returned. |
bool Grid::IsColumnFull | ( | int | index | ) |
Is column full?
Check whether a specific column is full.
[in] | index | Index of the column. |
void Grid::PreventColumnOverflow | ( | int | index | ) |
Prevent overflow.
Prevent a disc from being placed into a full column.
[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).
[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.
[out] | arr | An empty array which the grid array be written to. |