-
Notifications
You must be signed in to change notification settings - Fork 0
/
figure.cpp
73 lines (66 loc) · 1.73 KB
/
figure.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
#include "figure.h"
#include <QRandomGenerator>
Figure::Figure(uint r, uint c) {
m_i = r;
m_j = c;
fig.resize(3);
fig.fill(emptyCell);
cell = QApplication::desktop()->screenGeometry().width()/80;
}
Figure Figure::operator=(Figure &ref){
m_i = ref.m_i;
m_j = ref.m_j;
for(int i=0; i<3;i++)
fig[i] = ref.fig[i];
}
void Figure::setIndices(uint r, uint c) {
m_i = r;
m_j = c;
}
void Figure::getIndices(uint* indAr) {
indAr[0]=m_i;
indAr[1]=m_j;
}
void Figure::shiftColors(bool direction){
if(direction) {
QColor tmp = fig[2];
fig[2] = fig[1];
fig[1] = fig[0];
fig[0] = tmp;
}
else {
QColor tmp = fig[0];
fig[0] = fig[1];
fig[1] = fig[2];
fig[2] = tmp;
}
}
QVector<QColor> Figure::getColors() {
return fig;
}
QColor Figure::MakeRandomColor() {
QColor col;
value1 = QRandomGenerator::global()->generate();
switch(value1%7) {
case 0: return Qt::red;
case 1: return Qt::green;
case 2: return Qt::blue;
case 3: return Qt::yellow;
case 4: return Qt::white;
case 5: return Qt::black;
case 6: return Qt::magenta;
default: return emptyCell;
}
}
void Figure::MakeRandomColors(){
fig = {MakeRandomColor(), MakeRandomColor(), MakeRandomColor()};
}
void Figure::CleanFigure()
{
fig.fill(emptyCell);
}
void Figure::paintFigure(QPainter& painter){
painter.fillRect(m_j*cell, m_i*cell, (cell-2), (cell-2), QBrush(fig[0]));
painter.fillRect(m_j*cell, (m_i+1)*cell, (cell-2), (cell-2), QBrush(fig[1]));
painter.fillRect(m_j*cell, (m_i+2)*cell, (cell-2), (cell-2), QBrush(fig[2]));
}