ajouté interface textuelle
This commit is contained in:
@@ -12,6 +12,8 @@
|
||||
Piece::Piece(const Polyomino& polyomino, Block blockType) :
|
||||
polyomino(polyomino),
|
||||
blockType(blockType) {
|
||||
|
||||
this->rotationState = NONE;
|
||||
}
|
||||
|
||||
void Piece::rotate(Rotation rotation) {
|
||||
@@ -21,9 +23,22 @@ void Piece::rotate(Rotation rotation) {
|
||||
this->polyomino.rotate180();
|
||||
if (rotation == COUNTERCLOCKWISE)
|
||||
this->polyomino.rotateCCW();
|
||||
|
||||
this->rotationState += rotation;
|
||||
}
|
||||
|
||||
std::set<Position> Piece::getPositions() const {
|
||||
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<Position>& Piece::getPositions() const {
|
||||
return this->polyomino.getPositions();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,9 @@
|
||||
*/
|
||||
class Piece {
|
||||
private:
|
||||
Polyomino polyomino; // a polyomino representing the piece, (0, 0) is downleft
|
||||
Block blockType; // the block type of the piece
|
||||
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:
|
||||
/**
|
||||
@@ -28,9 +29,14 @@ class Piece {
|
||||
void rotate(Rotation rotation);
|
||||
|
||||
/**
|
||||
* @return A copy of the list of positions of the piece
|
||||
* Rotates the piece to its default rotation
|
||||
*/
|
||||
std::set<Position> getPositions() const;
|
||||
void defaultRotation();
|
||||
|
||||
/**
|
||||
* @return The list of positions of the piece
|
||||
*/
|
||||
const std::set<Position>& getPositions() const;
|
||||
|
||||
/**
|
||||
* @return The length of the piece
|
||||
|
||||
@@ -267,7 +267,7 @@ void Polyomino::tryToInsertPosition(std::set<Position>& emptyPositions, const Po
|
||||
tryToInsertPosition(emptyPositions, Position{candidate.x - 1, candidate.y});
|
||||
}
|
||||
|
||||
std::set<Position> Polyomino::getPositions() const {
|
||||
const std::set<Position>& Polyomino::getPositions() const {
|
||||
return this->positions;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ bool Polyomino::operator<(const Polyomino& other) const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Polyomino::operator ==(const Polyomino& other) const {
|
||||
bool Polyomino::operator==(const Polyomino& other) const {
|
||||
return this->positions == other.positions;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,9 +78,9 @@ class Polyomino {
|
||||
|
||||
public:
|
||||
/**
|
||||
* @return A copy of the positions of the polyomino
|
||||
* @return The positions of the polyomino
|
||||
*/
|
||||
std::set<Position> getPositions() const;
|
||||
const std::set<Position>& getPositions() const;
|
||||
|
||||
/**
|
||||
* @return The length of the polyomino
|
||||
@@ -103,7 +103,7 @@ class Polyomino {
|
||||
* Equality operator, two polyominos are equal if their positions are the same, that means two polyominos of the same shape at different places will not be equal
|
||||
* @return If the polyomino is equal to another
|
||||
*/
|
||||
bool operator ==(const Polyomino& other) const;
|
||||
bool operator==(const Polyomino& other) const;
|
||||
|
||||
/**
|
||||
* Stream output operator, adds a 2D grid representing the polyomino
|
||||
|
||||
@@ -62,6 +62,14 @@ inline bool operator==(const Position& left, const Position& right) {
|
||||
return (left.x == right.x) && (left.y == right.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Inequality operator, two positions aren't equal if their coordinates aren't
|
||||
* @return If the two positions aren't equals
|
||||
*/
|
||||
inline bool operator!=(const Position& left, const Position& right) {
|
||||
return (left.x != right.x) || (left.y != right.y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stream output operator, adds the coordinates of the position to the stream
|
||||
* @return A reference to the output stream
|
||||
|
||||
@@ -17,7 +17,7 @@ enum Rotation {
|
||||
* @return A rotation corresponding to doing both rotations
|
||||
*/
|
||||
inline Rotation operator+(const Rotation& left, const Rotation& right) {
|
||||
return Rotation((left + right) % 4);
|
||||
return Rotation(((int) left + (int) right) % 4);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user