Files
jminos/src/Pieces/Piece.h
2025-03-02 23:36:20 +01:00

57 lines
1.4 KiB
C++

#pragma once
#include "Polyomino.h"
#include "Rotation.h"
#include "Block.h"
#include "Color.h"
#include <set>
/**
* An abstraction of a polyomino as a playable piece in a stacker game
*/
class Piece {
private:
Polyomino polyomino; // a polyomino representing the piece, (0, 0) is downleft
Block blockType; // the block type of the piece
Rotation rotationState; // the current rotation of the piece
public:
/**
* Creates a piece with a specified shape and block type
*/
Piece(const Polyomino& piece, Block blockType);
/**
* Rotates the piece in the specified direction
*/
void rotate(Rotation rotation);
/**
* Rotates the piece to its default rotation
*/
void defaultRotation();
/**
* @return The list of positions of the piece
*/
const std::set<Position>& getPositions() const;
/**
* @return The length of the piece
*/
int getLength() const;
/**
* @return The block type of the piece
*/
Block getBlockType() const;
/**
* Stream output operator, adds a 2D grid representing the piece
* @return A reference to the output stream
*/
friend std::ostream& operator<<(std::ostream& os, const Piece& piece);
};