-
Notifications
You must be signed in to change notification settings - Fork 0
/
selection5_v.cpp
executable file
·237 lines (209 loc) · 9.23 KB
/
selection5_v.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#include "selection5_v.h"
#include "destroy.h"
#include "destroy_vertical.h"
#include "destroy_horizontal.h"
#include "selection_block.h"
#include "QDebug"
Selection5_V::Selection5_V()
{
}
void Selection5_V::selection(Grille *grille[N][N], Grille *clicked, int mode)
{
int row=clicked->row;
int col=clicked->col;
int num=clicked->tile;
int FiveNum[5]={0};
switch(mode)
{
case 1:// vertical normal component
clicked->tile=5;
if(col>=2&&((num==grille[row][col-2]->tile)||(num==grille[row][col-2]->tile/N))&&((num==grille[row][col-1]->tile)||(num==grille[row][col-1]->tile/N))){
grille[row][col-2]->tile=0;
grille[row][col-1]->tile=0;
}// left condition
if(col<=7&&((num==grille[row][col+1]->tile)||(num==grille[row][col+1]->tile/N))&&((num==grille[row][col+2]->tile)||(num==grille[row][col+2]->tile/N))){
grille[row][col+1]->tile=0;
grille[row][col+2]->tile=0;
}// right condition
if(grille[row-2][col]->tile/N!=0)FiveNum[0]=grille[row-2][col]->tile%N;
if(grille[row-1][col]->tile/N!=0)FiveNum[1]=grille[row-1][col]->tile%N;
FiveNum[2]=grille[row][col]->tile;
if(grille[row+1][col]->tile/N!=0)FiveNum[3]=grille[row+1][col]->tile%N;
if(grille[row+2][col]->tile/N!=0)FiveNum[4]=grille[row+2][col]->tile%N;
for(int i=0;i<5;i++){
Destroy * d;
switch(FiveNum[i]){
case 0:
grille[row-2+i][col]->tile=0;
break;
case 1:
d=new DestroyVertical;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
case 2:
d=new DestroyHorizontal;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
case 3:
d=new Selection_block;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
}
}
break;
case 2:// horizontal normal component
clicked->tile=5;
if(row>=2&&((num==grille[row-2][col]->tile)||(num==grille[row-2][col]->tile/N))&&((num==grille[row-1][col]->tile)||(num==grille[row-1][col]->tile/N))){
grille[row-2][col]->tile=0;
grille[row-1][col]->tile=0;
}// up condition
if(row<=7&&((num==grille[row+1][col]->tile)||(num==grille[row+1][col]->tile/N))&&((num==grille[row+2][col]->tile)||(num==grille[row+2][col]->tile/N))){
grille[row-2][col]->tile=0;
grille[row-1][col]->tile=0;
}// down condition
if(grille[row][col-2]->tile/N!=0)FiveNum[0]=grille[row][col-2]->tile%N;
if(grille[row][col-1]->tile/N!=0)FiveNum[1]=grille[row][col-1]->tile%N;
FiveNum[2]=grille[row][col]->tile;
if(grille[row][col+1]->tile/N!=0)FiveNum[3]=grille[row][col+1]->tile%N;
if(grille[row][col+2]->tile/N!=0)FiveNum[4]=grille[row][col+2]->tile%N;
for(int i=0;i<5;i++){
Destroy * d;
switch(FiveNum[i]){
case 0:
grille[row][col-2+i]->tile=0;
break;
case 1:
d=new DestroyVertical;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
case 2:
d=new DestroyHorizontal;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
case 3:
d=new Selection_block;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
}
}
break;
case 3:// DestroyVertical special component
num/=N;
if(col>=2&&((num==grille[row][col-2]->tile)||(num==grille[row][col-2]->tile/N))&&((num==grille[row][col-1]->tile)||(num==grille[row][col-1]->tile/N))){
grille[row][col-2]->tile=0;
grille[row][col-1]->tile=0;
}// left condition
if(col<=7&&((num==grille[row][col+1]->tile)||(num==grille[row][col+1]->tile/N))&&((num==grille[row][col+2]->tile)||(num==grille[row][col+2]->tile/N))){
grille[row][col+1]->tile=0;
grille[row][col+2]->tile=0;
}// right condition
if(grille[row-2][col]->tile/N!=0)FiveNum[0]=grille[row-2][col]->tile%N;
if(grille[row-1][col]->tile/N!=0)FiveNum[1]=grille[row-1][col]->tile%N;
FiveNum[2]=grille[row][col]->tile%N;
if(grille[row+1][col]->tile/N!=0)FiveNum[3]=grille[row+1][col]->tile%N;
if(grille[row+2][col]->tile/N!=0)FiveNum[4]=grille[row+2][col]->tile%N;
for(int i=0;i<5;i++){
Destroy * d;
switch(FiveNum[i]){
case 0:
grille[row-2+i][col]->tile=0;
break;
case 1:
d=new DestroyVertical;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
case 2:
d=new DestroyHorizontal;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
case 3:
d=new Selection_block;
d->elimination (grille,grille[row-2+i][col]);
delete d;
break;
}
}
break;
case 4:// DestroyHorizontal special component
num/=N;
if(row>=2&&((num==grille[row-2][col]->tile)||(num==grille[row-2][col]->tile/N))&&((num==grille[row-1][col]->tile)||(num==grille[row-1][col]->tile/N))){
grille[row-2][col]->tile=0;
grille[row-1][col]->tile=0;
}// up condition
if(row<=7&&((num==grille[row+1][col]->tile)||(num==grille[row+1][col]->tile/N))&&((num==grille[row+2][col]->tile)||(num==grille[row+2][col]->tile/N))){
grille[row-2][col]->tile=0;
grille[row-1][col]->tile=0;
}// down condition
if(grille[row][col-2]->tile/N!=0)FiveNum[0]=grille[row][col-2]->tile%N;
if(grille[row][col-1]->tile/N!=0)FiveNum[1]=grille[row][col-1]->tile%N;
FiveNum[2]=grille[row][col]->tile%N;
if(grille[row][col+1]->tile/N!=0)FiveNum[3]=grille[row][col+1]->tile%N;
if(grille[row][col+2]->tile/N!=0)FiveNum[4]=grille[row][col+2]->tile%N;
for(int i=0;i<5;i++){
Destroy * d;
switch(FiveNum[i]){
case 0:
grille[row][col-2+i]->tile=0;
break;
case 1:
d=new DestroyVertical;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
case 2:
d=new DestroyHorizontal;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
case 3:
d=new Selection_block;
d->elimination (grille,grille[row][col-2+i]);
delete d;
break;
}
}
break;
default:
qDebug()<<"spawn 5 error";
}
}
void Selection5_V::elimination(Grille *grille[10][10],Grille * focus)
{
// garbage function
}
int Selection5_V::condition(Grille *grille[10][10], Grille *focus)
{
int row= focus->row;
int col= focus->col;
int num= focus->tile;
if (num!=0 && num!=5)
{
if (num/10==0)
{
if (row>=2 && row<=7 && ((num==grille[row-2][col]->tile) || (num==grille[row-2][col]->tile/10)) && ((num==grille[row-1][col]->tile) || (num==grille[row-1][col]->tile/10)) && ((num==grille[row+1][col]->tile) || (num==grille[row+1][col]->tile/10)) && ((num==grille[row+2][col]->tile) || (num==grille[row+2][col]->tile/10)))
{return 1;}//vertical without bomb
if (col>=2 && col<=7 && ((num==grille[row][col-2]->tile) || (num==grille[row][col-2]->tile/10)) && ((num==grille[row][col-1]->tile) || (num==grille[row][col-1]->tile/10)) && ((num==grille[row][col+1]->tile) || (num==grille[row][col+1]->tile/10)) && ((num==grille[row][col+2]->tile) || (num==grille[row][col+2]->tile/10)))
{return 2;}//horizontal without bomb
}
else
{
num/=10;//determine the color
if (row>=2 && row<=7 && ((num==grille[row-2][col]->tile) || (num==grille[row-2][col]->tile/10)) && ((num==grille[row-1][col]->tile) || (num==grille[row-1][col]->tile/10)) && ((num==grille[row+1][col]->tile) || (num==grille[row+1][col]->tile/10)) && ((num==grille[row+2][col]->tile) || (num==grille[row+2][col]->tile/10)))
{return 3;}//vertical with bomb
if (col>=2 && col<=7 && ((num==grille[row][col-2]->tile) || (num==grille[row][col-2]->tile/10)) && ((num==grille[row][col-1]->tile) || (num==grille[row][col-1]->tile/10)) && ((num==grille[row][col+1]->tile) || (num==grille[row][col+1]->tile/10)) && ((num==grille[row][col+2]->tile) || (num==grille[row][col+2]->tile/10)))
{return 4;}//horizontal with bomb
}
}
return 0;
}
Selection5_V::~Selection5_V()
{
}