September 2018
Intermediate to advanced
328 pages
9h 10m
English
The second section of code contains logic to detect collisions:
bool Board::isCollision(const Piece &piece) const { for (int column = 0; column < PieceSize; ++column) { for (int row = 0; row < PieceSize; ++row) { if (piece.isBlock(column, row)) { int columnTarget = piece.getColumn() + column; int rowTarget = piece.getRow() + row; if ( columnTarget < 0 || columnTarget >= BoardColumns || rowTarget < 0 || rowTarget >= BoardRows ) { return true; } if (cells_[columnTarget][rowTarget]) return true; } } } return false;}
The isCollision() function loops through each cell on the board until it reaches one populated by the &piece passed as an argument. If the piece is about to collide with either side of the board or it has ...
Read now
Unlock full access