From 8da4c928ae36874ea4af4ab99bb665eb2ee93a5b Mon Sep 17 00:00:00 2001
From: Monoki Dorina <mondo1@cortex.itk.ppke.hu>
Date: Wed, 15 May 2024 18:50:37 +0200
Subject: [PATCH] elmenti a beirt adatokat es betolti legkozelebb

---
 application.cpp         |  2 ++
 fe1.txt => feladat.txt  |  0
 field.cpp               | 16 +++++++++++-----
 field.hpp               |  5 +++--
 gamemaster.cpp          | 13 +++++++++----
 gamemaster.hpp          |  3 ++-
 main.cpp                | 13 ++++++++++---
 mo1.txt => megoldas.txt |  0
 save.txt                |  1 +
 9 files changed, 38 insertions(+), 15 deletions(-)
 rename fe1.txt => feladat.txt (100%)
 rename mo1.txt => megoldas.txt (100%)
 create mode 100644 save.txt

diff --git a/application.cpp b/application.cpp
index 0e3f861..9092de2 100644
--- a/application.cpp
+++ b/application.cpp
@@ -68,12 +68,14 @@ void Application::event_loop()
                 }
 
                 std::set<int> aura_halmaz = _game->aura(focus);
+                // std::set<int> aura_ertekek;
 
                 for (int i=0; i<widgets.size(); i++)
                 {
                     if (aura_halmaz.find(i) != aura_halmaz.end())
                     {
                         action("aura",i,1);
+
                     }
                     else
                     {
diff --git a/fe1.txt b/feladat.txt
similarity index 100%
rename from fe1.txt
rename to feladat.txt
diff --git a/field.cpp b/field.cpp
index bc93165..096456d 100644
--- a/field.cpp
+++ b/field.cpp
@@ -4,10 +4,10 @@
 using namespace genv;
 
 Field::Field(Application* parent, int x, int y, int meret, int index, int ertek):
-    Widget(parent, x, y, meret, meret), _index(index), _ertek(ertek)
+    Widget(parent, x, y, meret, meret), _index(index), _ertek(ertek),
+    _fix(ertek), _aura(false), _helytelen(false)
 {
-    _fix=_ertek;
-    _aura=false;
+
 }
 
 void Field::rajzol() const
@@ -69,10 +69,16 @@ void Field::rajzol() const
         gout << move_to(_x, _y+_mag-2) << line(_szel,0);
 
     // szoveg
+
+    if (_helytelen)
+        gout << color(255,0,0);
+
+    gout << font("LiberationSans-Regular.ttf",_szel/3);
     if (_ertek)
     {
-         gout << move_to(_x+(_szel-gout.twidth(std::to_string(_ertek)))/2,
-                    _y+(_mag+gout.cascent())/2)
+         gout << move_to(_x+ (_szel-gout.twidth(std::to_string(_ertek)))/2,
+               _y+(_mag-gout.cascent()-gout.cdescent())/2)
+
          << text(std::to_string(_ertek));
 
          //gout << text(" ") << text(std::to_string(_aura));
diff --git a/field.hpp b/field.hpp
index cd02082..bff9f31 100644
--- a/field.hpp
+++ b/field.hpp
@@ -19,10 +19,11 @@ class Field : public Widget
 
     protected:
         int _ertek;
-        bool _fix;
-        bool _aura;
         int _index;
 
+        bool _fix;
+        bool _aura;
+        bool _helytelen;
 };
 
 #endif // FIELD_HPP
diff --git a/gamemaster.cpp b/gamemaster.cpp
index 3f95118..15d814b 100644
--- a/gamemaster.cpp
+++ b/gamemaster.cpp
@@ -6,13 +6,13 @@
 using namespace std;
 
 GameMaster::GameMaster(Application* parent, std::string mo, std::string fe) :
-    _parent(parent), _fajl_megoldas(mo), _fajl_feladat(fe)
+    _parent(parent), _fajl_megoldas(mo), _fajl_feladat(fe), _fajl_save("save.txt")
 {
     _parent->register_gm(this);
+
     _megoldas = fajl_beolvasas(_fajl_megoldas);
     _feladat = fajl_beolvasas(_fajl_feladat);
-    _save = _feladat;
-    _fajl_save = "save.txt";
+    _save = fajl_beolvasas(_fajl_save);
 
     // megmondja hogy melyik indexek melyik nagy negyzethez tartoznak
     _negyzetek.resize(9);
@@ -94,11 +94,16 @@ void GameMaster::save(int sorszam, int ertek)
     save_fajlba();
 }
 
-bool GameMaster::szabalyos_e(Index jelenlegi)
+bool GameMaster::szabalyos_e(int jelenlegi_ertek, set<int> ertekek)
 {
 
 }
 
+std::vector<int> GameMaster::get_feladat()
+{
+    return _feladat;
+}
+
 std::vector<int> GameMaster::get_save()
 {
     return _save;
diff --git a/gamemaster.hpp b/gamemaster.hpp
index 99bcadb..88cbbbc 100644
--- a/gamemaster.hpp
+++ b/gamemaster.hpp
@@ -16,12 +16,13 @@ class GameMaster
         void fajl_kiiras(std::string fajlnev, std::vector<int> v) const;
         void save_fajlba();
 
+        std::vector<int> get_feladat();
         std::vector<int> get_save();
         virtual void save(int,int);
 
         std::set<int> aura(Index);
         virtual int negyzet_szama(Index);
-        virtual bool szabalyos_e(Index);
+        virtual bool szabalyos_e(int,std::set<int>);
 
 
     protected:
diff --git a/main.cpp b/main.cpp
index 5b49589..eeb7ce9 100644
--- a/main.cpp
+++ b/main.cpp
@@ -6,6 +6,8 @@
 
 #include <vector>
 
+#define sorszam_i 9*j+i
+
 using namespace std;
 
 class MyApp : public Application
@@ -13,15 +15,20 @@ class MyApp : public Application
     public:
         MyApp(int szel, int mag) : Application(szel,mag)
         {
-            game = new GameMaster(this,"mo1.txt","fe1.txt");
-            vector<int> game_kezdo = game->get_save();
+            game = new GameMaster(this,"megoldas.txt","feladat.txt");
+            vector<int> game_feladat = game->get_feladat();
+            vector<int> game_save = game->get_save();
 
             for (int j=0; j<9; j++)  // sor
             {
                 for (int i=0; i<9; i++)  // oszlop
                 {
-                    Field *f = new Field(this,i*78,j*78,78,9*j+i,game_kezdo[9*j+i]);
+                    Field *f = new Field(this,i*78,j*78,78,sorszam_i,game_feladat[sorszam_i]);
                     palya.push_back(f);
+                    if (game_feladat[sorszam_i] == 0)
+                    {
+                        palya[sorszam_i]->set_ertek(game_save[sorszam_i]);
+                    }
                 }
             }
         }
diff --git a/mo1.txt b/megoldas.txt
similarity index 100%
rename from mo1.txt
rename to megoldas.txt
diff --git a/save.txt b/save.txt
new file mode 100644
index 0000000..e49992e
--- /dev/null
+++ b/save.txt
@@ -0,0 +1 @@
+0 8 5 6 0 1 0 0 0 0 0 6 5 4 0 0 2 1 0 0 0 0 3 0 0 0 0 8 0 7 9 0 4 1 0 0 0 3 0 5 0 7 9 8 6 1 9 0 8 0 0 0 0 0 0 0 3 0 7 0 6 0 0 0 2 0 0 8 5 3 0 0 7 0 8 3 0 6 0 0 0 
-- 
GitLab