-
Notifications
You must be signed in to change notification settings - Fork 1
/
RussiaBlockController.cpp
executable file
·142 lines (134 loc) · 3.88 KB
/
RussiaBlockController.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
#include "RussiaBlockController.h"
RussiaBlockController::RussiaBlockController(QObject *parent) :
QObject(parent)
{
}
bool RussiaBlockController::isBlocksInWindow(QList<QRect> theRectList, QRect theWindowRect,int x,int y)
{
int count = theRectList.count();
for(int i = 0;i<count;i++)
{
QRect tempBlockRect = QRect(theRectList[i]);
tempBlockRect.setX(tempBlockRect.x() + x);
tempBlockRect.setY(tempBlockRect.y() + y);
if(!theWindowRect.contains(tempBlockRect))
{
return false;
}
}
return true;
}
bool RussiaBlockController::isBlocksInsert(QList<QRect> theBlockRectList, QList<QRect> theWindowBlockRectList,int x,int y)
{
int BlocksCount = theBlockRectList.count();
for(int i = 0;i<BlocksCount;i++)
{
QRect tempBlockRect = QRect(theBlockRectList[i]);
tempBlockRect.setX(tempBlockRect.x() + x);
tempBlockRect.setY(tempBlockRect.y() + y);
tempBlockRect.setWidth(theBlockRectList[i].width());
tempBlockRect.setHeight(theBlockRectList[i].height());
int WindowBlockCount = theWindowBlockRectList.count();
for(int j = 0;j<WindowBlockCount;j++)
{
QRect tempWindowBlcokRect = QRect(theWindowBlockRectList[j]);
if(tempBlockRect.intersects(tempWindowBlcokRect))
{
return true;
}
}
}
return false;
}
int RussiaBlockController::GetBottomIndex(QList<QWidget *> &theBlockWidgets, int theY)
{
int result = theBlockWidgets.count();
int count = theBlockWidgets.count();
for(int i = 0 ;i < count; i++)
{
if(theY >= theBlockWidgets[i]->y())
{
result = i-1;
return i;
}
}
return result;
}
int RussiaBlockController::GetMarkAndClearBlock(QList<QWidget *> &theBlockWidgets, int theColumnCount)
{
if(theBlockWidgets.count() == 0)
{
return -1;
}
int theClearCount = 0;
int theBeginindex = 0;
int theheight = theBlockWidgets[0]->height();
while(theBeginindex != theBlockWidgets.count()-1)
{
int tempy = theBlockWidgets[0]->y();
bool theclearFlag = true;
int tempclearcount = 0;
for(int i = theBeginindex;i< theBeginindex+theColumnCount;i++)
{
if((theBlockWidgets[i]->y() != tempy))
{
theBeginindex = i;
theclearFlag = false;
break;
}
tempclearcount ++;
}
if(tempclearcount != theColumnCount)
{
theBeginindex += tempclearcount;
}
if(theclearFlag && tempclearcount == theColumnCount)
{
for(int i = 0;i<theColumnCount;i++)
{
theBlockWidgets.removeAt(theBeginindex);
theClearCount++;
}
for(int i = theBeginindex;theBlockWidgets.count();i++)
{
theBlockWidgets[i]->setGeometry(theBlockWidgets[i]->x(),theBlockWidgets[i]->y()+theheight,theBlockWidgets[i]->width(),theBlockWidgets[i]->height());
}
}
}
return theClearCount;
}
int RussiaBlockController::Min(int a, int b)
{
if(a<b)
{
return a;
}else
{
return b;
}
}
int RussiaBlockController::ProcessClearBlocks(QList<QWidget *> &theBlockWidgets)
{
int count = theBlockWidgets.count();
for(int i = 0; i <count;i++)
{
QWidget *temp = theBlockWidgets[i];
delete temp;
}
return count;
}
QString RussiaBlockController::GetResult(int theClearCount)
{
QString theSentence = "";
if(theClearCount < 60)
{
theSentence = "谁的猪蹄?";
}else if(theClearCount < 100)
{
theSentence = "终于有人来玩了!";
}else
{
theSentence = "灵巧的双手!Good Job!";
}
return QString("得分为%1\n%2").arg(theClearCount).arg(theSentence);
}