forked from navyamehta/enhancedgamedev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpieceI.cc
113 lines (109 loc) · 2.77 KB
/
pieceI.cc
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "pieceI.h"
#include "piece.h"
#include "cell.h"
#include <stdexcept>
#include <vector>
using namespace std;
PieceI::PieceI(vector<vector<unique_ptr<Cell>>> &t) {
this->disp = 'I';
for (int i=0; i < 4; i++) {
(this->ptr).push_back(t[3][i].get());
t[3][i]->setdisp('I');
t[3][i]->setbl(true);
}
}
void PieceI::transferPiece(std::vector<std::vector<unique_ptr<Cell>>> &src, std::vector<std::vector<unique_ptr<Cell>>> &des) {
for (int i=0; i < 4; i++) {
(this->ptr)[i]->setdisp(' ');
(this->ptr)[i]->setbl(false);
if (des[3][i]->getbl()) { throw invalid_argument("Game Over"); }
(this->ptr)[i] = des[3][i].get();
(this->ptr)[i]->setdisp('I');
(this->ptr)[i]->setbl(true);
}
}
PieceI::~PieceI() {}
void PieceI::rotate(bool cl) {
int anchor;
bool vert;
int row1 = (this->ptr)[0]->getrow();
int col1 = (this->ptr)[0]->getcol();
int row4 = (this->ptr)[3]->getrow();
int col4 = (this->ptr)[3]->getcol();
if (row1==row4) {
vert = false;
if (col1 < col4) {
anchor = 0;
}
else {
anchor = 3;
}
if (((cl)&&(row1>=15))||((!cl)&&(row1<=2))) {
return;
}
}
else if (col1==col4) {
vert = true;
if (row1 > row4) {
anchor = 0;
}
else {
anchor = 3;
}
if (((!cl)&&(col1<=2))||((cl)&&(col1>=8))) {
return;
}
}
if (anchor==0) {
Cell* temp = (this->ptr)[0];
for (int i=1; i<4; i++) {
if (vert) {
temp = cl?temp->getRight():temp->getLeft();
}
else {
temp = temp->getUp();
}
if (temp->getbl()) {
return;
}
}
for (int i=1; i<4; i++) {
(this->ptr)[i]->setdisp(' ');
(this->ptr)[i]->setbl(false);
if (vert) {
(this->ptr)[i] = cl?(this->ptr)[i-1]->getRight():(this->ptr)[i-1]->getLeft();
}
else {
(this->ptr)[i] = (this->ptr)[i-1]->getUp();
}
(this->ptr)[i]->setdisp(this->disp);
(this->ptr)[i]->setbl(true);
}
}
if (anchor==3) {
Cell* temp = (this->ptr)[3];
for (int i=3; i>=0; i--) {
if (vert) {
temp = cl?temp->getRight():temp->getLeft();
}
else {
temp = temp->getUp();
}
if (temp->getbl()) {
return;
}
}
for (int i=2; i>=0; i--) {
(this->ptr)[i]->setdisp(' ');
(this->ptr)[i]->setbl(false);
if (vert) {
(this->ptr)[i] = cl?(this->ptr)[i+1]->getRight():(this->ptr)[i+1]->getLeft();
}
else {
(this->ptr)[i] = (this->ptr)[i+1]->getUp();
}
(this->ptr)[i]->setdisp(this->disp);
(this->ptr)[i]->setbl(true);
}
}
}