63 lines
1.5 KiB
C++
63 lines
1.5 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(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 Polyomino& getPositions() const;
|
|
|
|
/**
|
|
* @param the position of the square
|
|
* @return false if there is a hole
|
|
*/
|
|
bool containsSquare(const Position& position) 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);
|
|
};
|