diff --git a/application.hpp b/application.hpp index b934e0f1ace7759aa51b44f2ed2febfe03ab460a..5ba4b7d02ccf84f794bb60ff0753fed908297022 100644 --- a/application.hpp +++ b/application.hpp @@ -2,6 +2,7 @@ #define APPLICATION_HPP #include "graphics.hpp" + #include <iostream> #include <vector> diff --git a/field.cpp b/field.cpp index 75c1aec7aa7bddcc00396c2bf27bee6bc2cbb55c..cb6942d5c6e26180f2d48edbf80044ae28caddf6 100644 --- a/field.cpp +++ b/field.cpp @@ -5,7 +5,7 @@ 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), - _fix(ertek), _aura(false), _helytelen(false) + _fix(ertek), _aura(false), _szabalyos(true) { } @@ -70,7 +70,7 @@ void Field::rajzol() const // szoveg - if (_helytelen) + if (!_szabalyos) gout << color(255,0,0); gout << font("LiberationSans-Regular.ttf",(_mag/5)*3); @@ -105,3 +105,8 @@ void Field::set_aura(bool be) { _aura=be; } + +void Field::set_szabalyos(bool be) +{ + _szabalyos=be; +} diff --git a/field.hpp b/field.hpp index bcc9593d35179e78667636eff721a56bc61a32aa..fac8cf641328ce485343e7bf6b47d62e7ad0bfb7 100644 --- a/field.hpp +++ b/field.hpp @@ -15,6 +15,7 @@ class Field : public Widget virtual void set_ertek(int); virtual void set_aura(bool); + virtual void set_szabalyos(bool); protected: int _ertek; @@ -22,7 +23,7 @@ class Field : public Widget bool _fix; bool _aura; - bool _helytelen; + bool _szabalyos; }; #endif // FIELD_HPP diff --git a/gamemaster.cpp b/gamemaster.cpp index 574e5cd9751e33b94cbb9ce4ffa2ed5b281ce2e1..2a2bd4db6568a5e2da9cc3cfee07647d11b131dd 100644 --- a/gamemaster.cpp +++ b/gamemaster.cpp @@ -58,6 +58,21 @@ set<int> GameMaster::aura(int jelenlegi_int) return s; } +vector<int> GameMaster::szabalytalan(int jelenlegi_ertek, vector<vector<int>> aura_ertekek) +{ + vector<int> v; + + for (int i=0; i<aura_ertekek.size(); i++) + { + if (aura_ertekek[i][1] == jelenlegi_ertek) + { + v.push_back(aura_ertekek[i][0]); + } + } + + return v; +} + int GameMaster::negyzet_szama(Index jelenlegi) { if (jelenlegi.sor <= 2) @@ -95,19 +110,6 @@ void GameMaster::save(int sorszam, int ertek) save_fajlba(); } -bool GameMaster::szabalyos_e(int jelenlegi_ertek, set<int> aura_ertekek) -{ - bool igen=true; - for (int ertek : aura_ertekek) - { - if (ertek == jelenlegi_ertek) - { - igen=false;; - } - } - return igen; -} - std::vector<int> GameMaster::get_feladat() { return _feladat; diff --git a/gamemaster.hpp b/gamemaster.hpp index 8127f965bef1d254e18ed80575af59f160ed6b8f..cf7152b3944bb825b6c808eca5b459148b899691 100644 --- a/gamemaster.hpp +++ b/gamemaster.hpp @@ -21,9 +21,8 @@ class GameMaster virtual void save(int,int); std::set<int> aura(int); + std::vector<int> szabalytalan(int,std::vector<std::vector<int>>); virtual int negyzet_szama(Index); - virtual bool szabalyos_e(int,std::set<int>); - protected: std::string _fajl_megoldas, _fajl_feladat, _fajl_save; diff --git a/myapp.cpp b/myapp.cpp index 06375e40a299e83027c42a0666cb59da5cfb9568..017699dbc44c2d1dae4a0c8780a749a633b38cc7 100644 --- a/myapp.cpp +++ b/myapp.cpp @@ -79,7 +79,6 @@ int MyApp::action(std::string id, genv::event ev, int focus) palya[focus]->kezel(ev); std::set<int> aura_halmaz = _game->aura(focus); - for (int i=0; i<palya.size(); i++) { if (aura_halmaz.find(i) != aura_halmaz.end()) @@ -96,11 +95,54 @@ int MyApp::action(std::string id, genv::event ev, int focus) if (ev.keycode >= 49 && ev.keycode <= 57) { palya[focus]->set_ertek(ev.keycode-48); + + std::set<int> aura_halmaz = _game->aura(focus); + vector<vector<int>> aura_ertekek; + for (int i=0; i<palya.size(); i++) + { + if (aura_halmaz.find(i) != aura_halmaz.end()) + { + aura_ertekek.push_back({i,palya[i]->get_ertek()}); + } + } + + vector<int> helytelenek = _game->szabalytalan(palya[focus]->get_ertek(),aura_ertekek); + + if (helytelenek.size() != 0) + { + palya[focus]->set_szabalyos(false); + for (int i=0; i<helytelenek.size(); i++) + { + palya[helytelenek[i]]->set_szabalyos(false); + } + } _game->save(focus,palya[focus]->get_ertek()); } if (ev.keycode==key_delete || ev.keycode==key_backspace) { + palya[focus]->set_szabalyos(true); + + /*std::set<int> aura_halmaz = _game->aura(focus); + vector<vector<int>> aura_ertekek; + for (int i=0; i<palya.size(); i++) + { + if (aura_halmaz.find(i) != aura_halmaz.end()) + { + aura_ertekek.push_back({i,palya[i]->get_ertek()}); + } + } + + vector<int> helytelenek = _game->szabalytalan(palya[focus]->get_ertek(),aura_ertekek); + + if (helytelenek.size() != 0) + { + for (int i=0; i<helytelenek.size(); i++) + { + palya[helytelenek[i]]->set_szabalyos(true); + } + }*/ + palya[focus]->set_ertek(0); _game->save(focus,palya[focus]->get_ertek()); } diff --git a/myapp.hpp b/myapp.hpp index e25ca75a6c33e3d983d9ff4bdfce145a83a8eb89..d2bf00174bc7929c1b98301228c3747ce82ab92c 100644 --- a/myapp.hpp +++ b/myapp.hpp @@ -5,7 +5,6 @@ #include "widget.hpp" #include "field.hpp" #include "gamemaster.hpp" -#include <vector> class MyApp : public Application {