#include "Piece.h" #include "Polyomino.h" #include "Rotation.h" #include "Block.h" #include "Color.h" #include #include Piece::Piece(const Polyomino& polyomino, Block blockType) : polyomino(polyomino), blockType(blockType) { this->rotationState = NONE; } void Piece::rotate(Rotation rotation) { if (rotation == CLOCKWISE) this->polyomino.rotateCW(); if (rotation == DOUBLE) this->polyomino.rotate180(); if (rotation == COUNTERCLOCKWISE) this->polyomino.rotateCCW(); this->rotationState += rotation; } void Piece::defaultRotation() { if (this->rotationState == CLOCKWISE) this->polyomino.rotateCCW(); if (this->rotationState == DOUBLE) this->polyomino.rotate180(); if (this->rotationState == COUNTERCLOCKWISE) this->polyomino.rotateCW(); this->rotationState = NONE; } const std::set& Piece::getPositions() const { return this->polyomino.getPositions(); } int Piece::getLength() const { return this->polyomino.getLength(); } Block Piece::getBlockType() const { return this->blockType; } std::ostream& operator<<(std::ostream& os, const Piece& piece) { os << getConsoleColorCode(piece.blockType) << piece.polyomino << getResetConsoleColorCode(); return os; }