The Board class

The Board contains instances of the Piece class and needs to detect collisions among the pieces, when rows are filled, and when the game is over. Let's start with the contents of the header file (board.h):

#ifndef TETRIS_BOARD_H
#define TETRIS_BOARD_H

#include <SDL2/SDL.h>
#include <SDL2/SDL2_ttf.h>
#include "constants.h"
#include "piece.h"

using namespace Constants;

class Board {
public:
Board();
void draw(SDL_Renderer *renderer, TTF_Font *font);
bool isCollision(const Piece &piece) const;
void unite(const Piece &piece);

private:
bool isRowFull(int row);
bool areFullRowsPresent();
void updateOffsetRow(int fullRow);
void displayScore(SDL_Renderer *renderer, TTF_Font *font);

bool cells_[BoardColumns][BoardRows];
int currentScore_;
};

#endif // TETRIS_BOARD_H

The Board has a draw() function like the Piece class as well as several other functions for managing rows and keeping track of which cells are populated on the board. The SDL2_ttf library is used to render the ROWS: text at the bottom of the window with the current score (count of rows cleared). Now, let's take a look at each section of the implementation file (board.cpp).

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

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