-
Notifications
You must be signed in to change notification settings - Fork 1
/
RowShape.cpp
176 lines (163 loc) · 4.6 KB
/
RowShape.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#include "RowShape.h"
#include "Board.h"
void RowShape::drawRow()
{
for (Point&p : body)
p.draw();
}
void RowShape::move(Board &boardGame, char keyPressed)
{
bool flag = true;
switch (adjust)
{
case HORIZON: // ------------------------------------- HORIZONTAL -------------------------------------
switch (keyPressed)
{
case eKEYS::DEFAULT:
for (int i = 0; i < SIZE; i++)
{
if (boardGame.isValid(body[i].getx(), body[i].gety() + 1) == false)
flag = false;
}
if (flag)
{
for (int i = 0; i < SIZE; i++)
{
boardGame.turnOffPoint(body[i].getx(), body[i].gety());
boardGame.turnOnPoint(body[i].getx(), body[i].gety() + 1);
}
updateRowShape(keyPressed);
}
break;
case eKEYS::LEFT:
if (boardGame.isValid(body[0].getx() - 1, body[0].gety()))
{
boardGame.turnOffPoint(body[3].getx(), body[3].gety());
boardGame.turnOnPoint(body[0].getx() - 1, body[0].gety());
updateRowShape(keyPressed);
}
break;
case eKEYS::RIGHT:
if (boardGame.isValid(body[3].getx() + 1, body[3].gety()))
{
boardGame.turnOffPoint(body[0].getx(), body[0].gety());
boardGame.turnOnPoint(body[3].getx() + 1, body[3].gety());
updateRowShape(keyPressed);
}
break;
case eKEYS::ROUTE: /* *
**** -> --*-
*
* */
if (boardGame.isValid(body[2].getx(), body[2].gety() - 1)
&& boardGame.isValid(body[2].getx(), body[2].gety() - 2)
&& boardGame.isValid(body[2].getx(), body[2].gety() + 1))
{
// TURN OFF
boardGame.turnOffPoint(body[0].getx(), body[0].gety());
boardGame.turnOffPoint(body[1].getx(), body[1].gety());
boardGame.turnOffPoint(body[3].getx(), body[3].gety());
// TURN ON
boardGame.turnOnPoint(body[2].getx(), body[2].gety() - 2);
boardGame.turnOnPoint(body[2].getx(), body[2].gety() - 1);
boardGame.turnOnPoint(body[2].getx(), body[2].gety() + 1);
updateRowShape(keyPressed);
}
break;
}
break;
case VERTICAL: // --------------------------------------- VERTICAL -----------------------------------------
switch (keyPressed)
{
case eKEYS::DEFAULT:
if (boardGame.isValid(body[3].getx(), body[3].gety() + 1))
{
boardGame.turnOffPoint(body[0].getx(), body[0].gety());
boardGame.turnOnPoint(body[3].getx(), body[3].gety() + 1);
updateRowShape(keyPressed);
}
break;
case eKEYS::LEFT:
for (int i = 0; i < SIZE; i++)
{
if (boardGame.isValid(body[i].getx() - 1, body[i].gety()) == false)
flag = false;
}
if (flag)
{
for (int i = 0; i < SIZE; i++)
{
boardGame.turnOffPoint(body[i].getx(), body[i].gety());
boardGame.turnOnPoint(body[i].getx() - 1, body[i].gety());
}
updateRowShape(keyPressed);
}
break;
case eKEYS::RIGHT:
for (int i = 0; i < SIZE; i++)
{
if (boardGame.isValid(body[i].getx() + 1, body[i].gety()) == false)
flag = false;
}
if (flag)
{
for (int i = 0; i < SIZE; i++)
{
boardGame.turnOffPoint(body[i].getx(), body[i].gety());
boardGame.turnOnPoint(body[i].getx() + 1, body[i].gety());
}
updateRowShape(keyPressed);
}
break;
case eKEYS::ROUTE:
if (boardGame.isValid(body[2].getx() - 2, body[2].gety())
&& boardGame.isValid(body[2].getx() - 1, body[2].gety())
&& boardGame.isValid(body[2].getx() + 1, body[2].gety()))
{
// TURN OFF
boardGame.turnOffPoint(body[0].getx(), body[0].gety());
boardGame.turnOffPoint(body[1].getx(), body[1].gety());
boardGame.turnOffPoint(body[3].getx(), body[3].gety());
// TURN ON
boardGame.turnOnPoint(body[2].getx() - 2, body[2].gety());
boardGame.turnOnPoint(body[2].getx() - 1, body[2].gety());
boardGame.turnOnPoint(body[2].getx() + 1, body[2].gety());
updateRowShape(keyPressed);
}
}
}
}
void RowShape::updateRowShape(char direction)
{
switch (direction)
{
case eKEYS::DEFAULT:
for (Point&p : body)
p.setPoint(p.getx(), p.gety() + 1, true);
break;
case eKEYS::LEFT:
for (Point&p : body)
p.setPoint((p.getx()) - 1, p.gety(), true);
break;
case eKEYS::RIGHT:
for (Point&p : body)
p.setPoint((p.getx()) + 1, p.gety(), true);
break;
case eKEYS::ROUTE:
if (adjust == HORIZON)
{
body[0].setPoint(body[2].getx(), body[2].gety() - 2, true);
body[1].setPoint(body[2].getx(), body[2].gety() - 1, true);
body[3].setPoint(body[2].getx(), body[2].gety() + 1, true);
this->adjust = VERTICAL;
}
else
{
body[0].setPoint(body[2].getx() - 2, body[2].gety(), true);
body[1].setPoint(body[2].getx() - 1, body[2].gety(), true);
body[3].setPoint(body[2].getx() + 1, body[2].gety(), true);
this->adjust = HORIZON;
}
break;
}
}