From f9ca900a42779c55d2bc87d549408adb33461d8f Mon Sep 17 00:00:00 2001
From: "fodor.agoston" <fodor.agoston@hallgato.ppke.hu>
Date: Sat, 18 May 2024 13:54:56 +0200
Subject: [PATCH] =?UTF-8?q?p=C3=A1lya=20bet=C3=B6lt=C3=A9s=20kezdetlegesen?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 application.cpp | 17 ++++++++---------
 main.cpp        | 34 +++++++++++++++++++++++++++-------
 spinbox.cpp     |  4 ++--
 spinbox.hpp     |  2 +-
 4 files changed, 38 insertions(+), 19 deletions(-)

diff --git a/application.cpp b/application.cpp
index 6a8a4c8..f5e5bb8 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 b1c9ef4..b75b955 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 8c45bd2..bab81c3 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 31ccf41..f041134 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;
-- 
GitLab