biquadris / baseboard.h
baseboard.h
Raw
/*
    BaseBoard class module
    
    the base of the Board that stores information of cells and blocks from
    their generation, movement, and the game implementation
*/

#ifndef _BASEBOARD_H_
#define _BASEBOARD_H_

#include <vector>
#include <memory>
#include <utility>
#include <fstream>
#include <string>
#include "board.h"
#include "subscriptions.h"

class BiquadrisModel;
class Scoreboard;
class Level;
class Block;
class Cell;
class Board;

class Subject;

class BaseBoard: public Board {
    std::vector<std::vector<std::shared_ptr<Cell>>> theGrid;
    int width, height, seed, level, boardId, movesWithoutClearing, lastNumLinesCleared;
    Scoreboard *sb;
    BiquadrisModel *m;
    std::shared_ptr<Block> currentBlock;
    std::vector<std::shared_ptr<Block>> blocks;
    std::unique_ptr<Level> currentLevel;
    std::pair<char, int> nextBlock;
    std::string theHint;

    void deleteLine(int line);
    void generateNextBlock(); // note: once generated, level cannot change
    int clearLine(); // note: clearLine() returns the number of lines cleared
    void blocksCleanup();
    void init();
    public:
        BaseBoard(int width, int height, int seed, int level, int boardId,
                  Scoreboard *sb, BiquadrisModel *m, std::string seq);
        ~BaseBoard();
        std::shared_ptr<Board> getComponent() override;

        void move(char direction, int n, int weight) override;
        void rotate(bool isClockwise, int n, int weight) override;
        void drop() override;
        
        void placeCurrBlock() override; // places nextBlock to the upper left

        // replaceCurrBlock(type, safety) replaces currentBlock with another 
        //  block at the same position if possible, will throw InvalidPlacement
        //  otherwise
        void replaceCurrBlock(char type, bool safety = true) override; 

        int getLevel() const noexcept override;
        int getWidth() const noexcept override;
        int getHeight() const noexcept override;
        int getBoardId() const noexcept override; 
        char getNextBlock() const noexcept override;
        int getLastNumLinesCleared() const noexcept override;
        char getType(int row, int col) override;
        std::string getHint();
        void hint() override;

        Block* getBlock(int row, int col) override;

        // drawBlock(row, col, b) fill the cell at row, col with block b
        void drawBlock(int row, int col, Block *block) override;

        // eraseBlock(row, col) removes the block from cell at row, col
        void eraseBlock(int row, int col) override;

        void levelUp() override;
        void levelDown() override;

        // setSequence(file) sets the sequence for the generation of blocks
        void setSequence(std::string file) override;
        void setRandom(bool r);

        void restart() override;
}; 

#endif