Files
jminos/src/Core/Board.h
2025-02-25 19:21:08 +01:00

64 lines
1.6 KiB
C++

#pragma once
#include "../Pieces/Piece.h"
#include <vector>
#include <iostream>
/**
* A 2D grid of blocks
*/
class Board {
private:
std::vector<std::vector<ColorEnum>> grid; // the grid, (0,0) is downleft
int width; // the width of the grid
int height; // the base height of the grid, which can extends indefinitely
public:
/**
* Creates a new board of the specified size
*/
Board(int width, int height);
/**
* Change the color of the specified block, if the block is out of bounds it is simply ignored
*/
void addBlock(const Cell& position, ColorEnum block);
/**
* Clears any complete row and moves down the rows on top, returns the number of cleared rows
*/
int clearRows();
/**
* Returns the color of the block at the specified position
*/
ColorEnum getBlock(const Cell& position) const;
/**
* Returns a copy of the grid
*/
std::vector<std::vector<ColorEnum>> getBlocks() const;
/**
* Returns the actual height of the grid
*/
int getGridHeight() const;
/**
* Returns the base height of the grid
*/
int getBaseHeight() const;
/**
* Returns the width of the grid
*/
int getWidth() const;
/**
* Stream output operator, adds a 2D grid representing the board
*/
friend std::ostream& operator<<(std::ostream& os, const Board& board);
};