The constructor and draw() function

The first section of code defines the constructor of the Board class and the draw() function:

#include <sstream>
#include "board.h"

using namespace Constants;

Board::Board() : cells_{{ false }}, currentScore_(0) {}

void Board::draw(SDL_Renderer *renderer, TTF_Font *font) {
displayScore(renderer, font);
SDL_SetRenderDrawColor(
renderer,
/* Light Gray: */ 140, 140, 140, 255);
for (int column = 0; column < BoardColumns; ++column) {
for (int row = 0; row < BoardRows; ++row) {
if (cells_[column][row]) {
SDL_Rect rect{
column * Offset + 1,
row * Offset + 1,
Offset - 2,
Offset - 2
};
SDL_RenderFillRect(renderer, &rect);
}
}
}
}

The Board constructor initializes the values of the private cells_ and currentScore_ variables to default values. The cells_ variable is a two-dimensional array of Booleans, with the first dimension representing columns and the second rows. If a piece occupies a specific column and row, the corresponding value in the array is true. The draw() function behaves similarly to the draw() function of Piece in that it fills cells that contain pieces with color. However, this function only fills in cells that are occupied by pieces that have reached the bottom of the board with a light gray color, regardless of what kind of piece it is.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset