0% found this document useful (0 votes)
9 views3 pages

Board H

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views3 pages

Board H

Uploaded by

wijifal264
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#ifndef BOARD_H

#define BOARD_H
#include <iomanip>
#include <vector>
#include "Cell.h"
#include "Position.h"
#include "Observable.h"

using namespace std;

namespace Tetris
{

class Brick;// early declaration

/**
* @brief Represents the game board in Tetris.
*/
class Board : public Observable {
public:
/**
* @brief Deleted default constructor.
*/
Board() = delete ;
/**
* @brief Constructs a new game board with the specified dimensions.
* @param rows The number of rows in the board.
* @param cols The number of columns in the board.
* @param partially_filled Whether the board is partially filled or not
*/
Board(const unsigned& rows, const unsigned& cols,const bool
partially_filled) ;
/**
* @brief Retrieves the height of the board.
* @return The height of the board.
*/
inline const unsigned& getHeight() const {return height;}
/**
* @brief Retrieves the width of the board.
* @return The width of the board.
*/
inline const unsigned& getWidth() const {return width;}
/**
* @brief Checks if a cell at the specified position is occupied.
* @param pos The position of the cell to check.
* @return True if the cell is occupied, false otherwise.
*/
const bool isPositionOccupied(const Position &pos)const;
/**
* @brief Checks if a cell at the specified position is occupied.
* @param pos The position of the cell to check.
* @return True if the cell is occupied, false otherwise.
*/
const bool isPositionCurrent(const Position &pos)const ;
/**
* @brief Checks if a row is complete and needs to be removed.
* @param rowIndex The index of the row to check.
* @return True if the row is complete, false otherwise.
*/
bool checkCompleteRow(const unsigned& rowIndex);
/**
* @brief Generates a random boolean value based on the given probability.
* @param probabilityNumerator Numerator of the probability fraction.
* @param probabilityDenominator Denominator of the probability fraction.
* @return True if the randomly generated value satisfies the probability
condition, false otherwise.
*/
bool randomBoolean(int probabilityNumerator, int probabilityDenominator);
/**
* @brief Overloaded operator= to prevent assigning another Board object.
* @param board The Board object to copy from.
* @return Reference to the original Board object.
*/
inline Board& operator=(const Board& board) { return *this; }
/**
* @brief Deleted to prevent assignment from nullptr.
*/
Board& operator=(const std::nullptr_t) = delete;
/**
* @brief Overloaded operator[] to prevent modification of rows.
* @param row The index of the row.
* @return A constant reference to the vector of cells representing the
row.
*/
const std::vector<Cell>& operator[](unsigned row) const { return
board[row]; }

private:
/**
* @brief Removes a row from the board.
* @param rowIndex The index of the row to be removed.
*/
void deleteRow(unsigned rowIndex);
/**
* @brief Sets the occupancy status of a cell at the specified position.
* @param pos The position of the cell to set.
* @param status The new occupancy status.
*/
void setCellOccupancy(const Position &pos, const bool &status);
/**
* @brief Sets the current cell status of a cell at the specified position.
* @param pos The position of the cell to set.
* @param status The new current cell status.
*/
void setCellCurrent(const Position &pos, const bool &status);
/**
* @brief Places a brick on the board.
* @param brick The brick to place on the board.
* @return true if it can be placed
*/
bool placeBrick(const Brick& brick);
/**
* @brief Resets cells at the specified positions if they are occupied.
* @param positions Vector of positions of cells to reset.
*/
void resetCells(const vector<Position>& positions);
/**
* @brief Partially fills the board with occupied cells randomly.
*/
void partiallyFill();

friend class Brick;


friend class Game;
friend class BoardTest;

unsigned height; ///< The height of the board.


unsigned width; ///< The width of the board.
std::vector<std::vector<Cell>> board; ///< The 2D vector representing the
cells of the board.
};

} // Tetris

#endif // BOARD_H

You might also like