-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainwindow.cpp
164 lines (147 loc) · 3.16 KB
/
mainwindow.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
#include "mainwindow.h"
#include "ui_mainwindow.h"
sudoku::matrix matx;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
matx.new_puzzle();
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
QTableWidgetItem* Cell = ui->table->item(i, j);
QString str = "";
str += '0' + matx.read(i, j);
const QString cstr = str;
Cell->setText(cstr);
if (matx.read(i, j))
{
QColor c(122,122,235);
Cell->setBackgroundColor(c);
}
}
}
ui->label->setText("sudoku!!");
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_table_cellClicked(int row, int column)
{
Row = row;
Column = column;
QString str = "";
str += '0' + row;
str += ',';
str += '0' + column;
const QString cstr = str;
ui->label->setText(cstr);
}
void MainWindow::click__on_pb(int num)
{
QTableWidgetItem* Cell = ui->table->item(Row, Column);
matx.write(Row, Column, num);
QString str = "";
str += '0' + matx.read(Row, Column);
const QString cstr = str;
Cell->setText(cstr);
if (matx.you_win())
{
ui->label->setText("you win!!");
}
}
void MainWindow::on_pb00_1_clicked()
{
click__on_pb(1);
}
void MainWindow::on_pb00_2_clicked()
{
click__on_pb(2);
}
void MainWindow::on_pb00_3_clicked()
{
click__on_pb(3);
}
void MainWindow::on_pb00_4_clicked()
{
click__on_pb(4);
}
void MainWindow::on_pb00_5_clicked()
{
click__on_pb(5);
}
void MainWindow::on_pb00_6_clicked()
{
click__on_pb(6);
}
void MainWindow::on_pb00_7_clicked()
{
click__on_pb(7);
}
void MainWindow::on_pb00_8_clicked()
{
click__on_pb(8);
}
void MainWindow::on_pb00_9_clicked()
{
click__on_pb(9);
}
void MainWindow::on_solve_clicked()
{
matx.reset();
matx.solve();
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
QTableWidgetItem* Cell = ui->table->item(i, j);
QString str = "";
str += '0' + matx.read(i,j);
const QString cstr = str;
Cell->setText(cstr);
}
}
}
void MainWindow::on_actionNew_game_triggered()
{
matx.new_puzzle();
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
QTableWidgetItem* Cell = ui->table->item(i, j);
QString str = "";
str += '0' + matx.read(i, j);
const QString cstr = str;
Cell->setText(cstr);
if (matx.read(i, j))
{
QColor c(122,122,235);
Cell->setBackgroundColor(c);
}
else
{
QColor c(255,255,255);
Cell->setBackgroundColor(c);
}
}
}
}
void MainWindow::on_pushButton_clicked()
{
matx.reset();
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
QTableWidgetItem* Cell = ui->table->item(i, j);
QString str = "";
str += '0' + matx.read(i, j);
const QString cstr = str;
Cell->setText(cstr);
}
}
}