diff --git a/application.cpp b/application.cpp index 6a8a4c84e867498a9cacbdbc1a880ee9eae37836..f5e5bb860edaffafbd8cf1cbf5987f6b1cae294a 100644 --- a/application.cpp +++ b/application.cpp @@ -50,10 +50,10 @@ void Application::event_loop() if (focus != -1) { widgets[focus]->handle(ev); for (int k = 0; k < 81; k += 9) { - for (int i = k; i < 9+k; ++i) { - for (size_t j = i+1; j < 9+k; ++j) { - if (widgets[i]->getter() == widgets[j]->getter()) { - wrongi = j; + for (int i = k; i < 9 + k; ++i) { + for (int j = i + 1; j < 9 + k; ++j) { + if (widgets[i]->getter() != 0 && widgets[i]->getter() == widgets[j]->getter()) { + wrongi = i; break; } } @@ -66,12 +66,11 @@ void Application::event_loop() } } - for (int k = 0; k < 9; ++k) { for (int i = k; i < 81; i += 9) { - for (size_t j = i+9; j < 81; j += 9) { - if (widgets[i]->getter() == widgets[j]->getter()) { - wrongi = j; + for (int j = i + 9; j < 81; j += 9) { + if (widgets[i]->getter() != 0 && widgets[i]->getter() == widgets[j]->getter()) { + wrongi = i; break; } } @@ -123,7 +122,7 @@ void Application::event_loop() } } gout << refresh; - std::cout << widgets[11]->getter() << std::endl; + } } diff --git a/main.cpp b/main.cpp index b1c9ef4641098de54e97cd7d0f641455632fa1be..b75b9553e543c42cad3fca0a934690c561e52a7f 100644 --- a/main.cpp +++ b/main.cpp @@ -1,8 +1,8 @@ -#include <iostream> + #include "application.hpp" #include "spinbox.hpp" #include <vector> -#include "widget.hpp" + using namespace genv; using namespace std; @@ -17,23 +17,43 @@ public: void palya() { + vector<vector<int>> board = { + {5, 3, 0, 0, 7, 0, 0, 0, 0}, + {6, 0, 0, 1, 9, 5, 0, 0, 0}, + {0, 9, 8, 0, 0, 0, 0, 6, 0}, + {8, 0, 0, 0, 6, 0, 0, 0, 3}, + {4, 0, 0, 8, 0, 3, 0, 0, 1}, + {7, 0, 0, 0, 2, 0, 0, 0, 6}, + {0, 6, 0, 0, 0, 0, 2, 8, 0}, + {0, 0, 0, 4, 1, 9, 0, 0, 5}, + {0, 0, 0, 0, 8, 0, 0, 7, 9} + }; + for (int i = 0; i < 9; ++i) { - vector<SpinBox*> rowWidgets; // Az adott sorhoz tartozó SpinBox-ok + vector<SpinBox*> rowWidgets; for (int j = 0; j < 9; ++j) { - SpinBox* sp = new SpinBox(this, 5 + j * 100, 5 + i * 100, 100, 0, 9); - rowWidgets.push_back(sp); // Hozzáadjuk az új SpinBox-ot az aktuális sorhoz + SpinBox* spin; + if (board[i][j] != 0) + { + spin = new SpinBox(this, 5 + j * 100, 5 + i * 100, 100, board[i][j], board[i][j], board[i][j]); + } + else + { + spin = new SpinBox(this, 5 + j * 100, 5 + i * 100, 100, 0, 9,0); + } + rowWidgets.push_back(spin); } - // Hozzáadjuk az aktuális sorhoz tartozó widgeteket a teljes widget listához + widgets.push_back(rowWidgets); } } protected: - vector<vector<SpinBox*>> widgets; // Kétdimenziós vektor a sorok és oszlopok kezelésére + vector<vector<SpinBox*>> widgets; }; int main() diff --git a/spinbox.cpp b/spinbox.cpp index 8c45bd27e48c0c38e3746b6cfd3563c23101ab8a..bab81c3d24b8f885d8370bd1d2fabc91938fb2d4 100644 --- a/spinbox.cpp +++ b/spinbox.cpp @@ -9,9 +9,9 @@ using namespace std; int mouse_x = 0; int mouse_y = 0; -SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max) : Widget(parent,x,y,sizey*3,sizey), _min(min), _max(max), _isselected(0) +SpinBox::SpinBox(Application* parent,int x, int y, int sizey, int min, int max, int start) : Widget(parent,x,y,sizey*3,sizey), _min(min), _max(max), _num(start), _isselected(0) { - _num = 0; + } void SpinBox::draw() diff --git a/spinbox.hpp b/spinbox.hpp index 31ccf4134431df2bb2aa6c05d0bec54ffbace3c7..f0411349bce278937c3382091d91874956f4a951 100644 --- a/spinbox.hpp +++ b/spinbox.hpp @@ -10,7 +10,7 @@ protected: bool _isselected; public: - SpinBox(Application* ,int, int, int,int, int); + SpinBox(Application* ,int, int, int,int, int,int); void draw() override; void handle(genv::event) override;