-
Notifications
You must be signed in to change notification settings - Fork 0
/
Drawer.cpp
116 lines (102 loc) · 2.95 KB
/
Drawer.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
#include "Drawer.h"
#include <QThread>
#include <QApplication>
QTableWidget* Drawer::board_;
int** Drawer::currentState_;
int Drawer::speed_ = 1;
void Drawer::SetInitialState(int** initialState)
{
currentState_ = initialState;
}
void Drawer::Draw(int** state)
{
for (int row = 0; row < 9; row++)
{
for (int col = 0; col < 9; col++)
{
if (board_->item(row, col)->backgroundColor() == QColor("orange")
|| board_->item(row, col)->backgroundColor() == QColor("red"))
{
board_->item(row, col)->setBackgroundColor("white");
}
if (state[row][col] != board_->item(row, col)->data(QVariant::Int))
{
if (state[row][col] == 0)
{
board_->item(row, col)->setBackgroundColor("orange");
}
else
{
board_->item(row, col)->setBackgroundColor("lightgreen");
}
}
board_->item(row, col)->setData(QVariant::Int, state[row][col]);
}
}
QCoreApplication::processEvents();
QThread::msleep(speed_);
}
void Drawer::DrawBackTrack(int** state)
{
for (int row = 0; row < 9; row++)
{
for (int col = 0; col < 9; col++)
{
if (state[row][col] != board_->item(row, col)->data(QVariant::Int))
{
board_->item(row, col)->setBackgroundColor("orange");
QCoreApplication::processEvents();
QThread::msleep(speed_);
QCoreApplication::processEvents();
}
board_->item(row, col)->setData(QVariant::Int, state[row][col]);
}
}
}
void Drawer::HighlightContradiction(int row, int col)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (i == row || j == col)
{
board_->item(i, j)->setBackgroundColor("red");
}
}
}
QCoreApplication::processEvents();
QThread::msleep(speed_ * 7);
QCoreApplication::processEvents();
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (board_->item(i,j)->backgroundColor() == QColor("red"))
{
QString newColor = (board_->item(i,j)->data(QVariant::Int) == 0) ? "white" : "lightgreen";
board_->item(i, j)->setBackgroundColor("white");
}
}
}
}
void Drawer::GameComplete()
{
QCoreApplication::processEvents();
SetAllSquaresToColor("lightgreen");
QCoreApplication::processEvents();
}
void Drawer::SetAllSquaresToColor(QString color)
{
for (int i = 0; i < 9; i++)
{
for (int j = 0; j < 9; j++)
{
if (board_->item(i, j)->backgroundColor() != QColor(color))
{
board_->item(i, j)->setBackgroundColor(color);
QThread::msleep(speed_);
}
}
}
}