summaryrefslogtreecommitdiff
path: root/src/piece.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/piece.cpp')
-rw-r--r--src/piece.cpp70
1 files changed, 37 insertions, 33 deletions
diff --git a/src/piece.cpp b/src/piece.cpp
index 67755f0..d686a32 100644
--- a/src/piece.cpp
+++ b/src/piece.cpp
@@ -1,39 +1,7 @@
#include "piece.h"
Piece::Piece(Piece::PieceType type, int xpos){
- switch (type){
- case PieceType::LINE:
- blocks[0] = { 1, 0 };
- blocks[1] = { 1, 1 };
- blocks[2] = { 1, 2 };
- blocks[3] = { 1, 3 };
- break;
- case PieceType::BLOCK:
- blocks[0] = { 1, 1 };
- blocks[1] = { 1, 2 };
- blocks[2] = { 2, 1 };
- blocks[3] = { 2, 2 };
- break;
- case PieceType::S:
- blocks[0] = { 1, 0 };
- blocks[1] = { 1, 1 };
- blocks[2] = { 1, 2 };
- blocks[3] = { 1, 3 };
- break;
- case PieceType::T:
- blocks[0] = { 1, 0 };
- blocks[1] = { 1, 1 };
- blocks[2] = { 1, 2 };
- blocks[3] = { 1, 3 };
- break;
- case PieceType::L:
- blocks[0] = { 1, 0 };
- blocks[1] = { 1, 1 };
- blocks[2] = { 1, 2 };
- blocks[3] = { 1, 3 };
- break;
- }
- position_ = {xpos, 0};
+ restartTo(type, xpos);
}
void Piece::initIterator(){
@@ -75,3 +43,39 @@ void Piece::move_left(){
void Piece::move_right(){
position_.x++;
}
+
+void Piece::restartTo(PieceType type, int xpos){
+ switch (type){
+ case PieceType::LINE:
+ blocks[0] = { 1, 0 };
+ blocks[1] = { 1, 1 };
+ blocks[2] = { 1, 2 };
+ blocks[3] = { 1, 3 };
+ break;
+ case PieceType::BLOCK:
+ blocks[0] = { 1, 1 };
+ blocks[1] = { 1, 2 };
+ blocks[2] = { 2, 1 };
+ blocks[3] = { 2, 2 };
+ break;
+ case PieceType::S:
+ blocks[0] = { 1, 0 };
+ blocks[1] = { 1, 1 };
+ blocks[2] = { 2, 1 };
+ blocks[3] = { 2, 2 };
+ break;
+ case PieceType::T:
+ blocks[0] = { 1, 0 };
+ blocks[1] = { 1, 1 };
+ blocks[2] = { 1, 2 };
+ blocks[3] = { 2, 1 };
+ break;
+ case PieceType::L:
+ blocks[0] = { 1, 0 };
+ blocks[1] = { 1, 1 };
+ blocks[2] = { 1, 2 };
+ blocks[3] = { 2, 2 };
+ break;
+ }
+ position_ = {xpos, 0};
+}