-
Notifications
You must be signed in to change notification settings - Fork 0
/
Piece.cpp
48 lines (45 loc) · 1.13 KB
/
Piece.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by daily on 03-01-24.
//
#include "Piece.h"
Piece::Piece(int pieceType) : blocks(), type(pieceType) {
blocks.emplace_back(0, 0, type);
blocks.emplace_back(0, 1, type);
blocks.emplace_back(1, 0, type);
blocks.emplace_back(1, 1, type);
}
Piece::Piece(const std::vector<Block>& newBlocks, int newType): blocks(newBlocks), type(newType){
}
void Piece::rotate() {
Block pivot = blocks[0];
for (auto& block : blocks) {
int newX = pivot.getX() - (block.getY() - pivot.getY());
int newY = pivot.getY() + (block.getX() - pivot.getX());
block.setX(newX);
block.setY(newY);
}
}
void Piece::moveLeft() {
for (auto& block : blocks) {
block.setX(block.getX() - 1);
}
}
void Piece::moveRight() {
for (auto& block : blocks) {
block.setX(block.getX() + 1);
}
}
std::vector<Block> Piece::getBlocks() const {
return blocks;
}
int Piece::getType() const {
return type;
}
void Piece::setBlocks(const std::vector<Block>& newBlocks){
blocks = newBlocks;
}
void Piece::dropBlocks() {
for (auto& block : blocks) {
block.setY(block.getY() + 1);
}
}