diff --git a/application.cpp b/application.cpp index 02f66d315e2a47c7f0e4b1414267b3ce066e4b08..32da0633db9a5c13391a7c2c69d2b306cbe2f7f5 100644 --- a/application.cpp +++ b/application.cpp @@ -16,7 +16,6 @@ void Application::event_loop() { event ev; int focus = action("start", ev, 0); - widgets[focus]->kezel(ev); for (Widget *w : widgets) { diff --git a/button.cpp b/button.cpp deleted file mode 100644 index 60adeeba4385a8c81e372b3cfa6cb3c7a4e41922..0000000000000000000000000000000000000000 --- a/button.cpp +++ /dev/null @@ -1,42 +0,0 @@ -#include "button.hpp" - -using namespace genv; - -Button::Button(Application* parent, int x, int y, int szel, int mag, - std::string cimke, std::function<void()> f): - Widget(parent, x, y, szel, mag), _cimke(cimke), _f(f) {} - - -void Button::rajzol() const -{ - // hatter - gout << color(dark_purple); - gout << move_to(_x,_y) << box(_szel,_mag); - - // keret - gout << color(light_purple); - gout << move_to(_x,_y) << line(_szel,0) << line(0,_mag) << line(-_szel,0) << line(0,-_mag); - - // szoveg - gout << font("LiberationSans-Regular.ttf",20); - - gout << move_to(_x+ (_szel-gout.twidth(_cimke))/2, - _y+(_mag-gout.cascent()-gout.cdescent())/2) - - << text(_cimke); -} - -void Button::kezel(event ev) -{ - if (ev.type == ev_mouse && ev.button==btn_left - && belul(ev.pos_x,ev.pos_y)) - { - action(); - } -} - -void Button::action() -{ - _f(); -} - diff --git a/button.hpp b/button.hpp deleted file mode 100644 index 7b0034408eb4d3c9e5b7f2aa9c1bbe0084c77203..0000000000000000000000000000000000000000 --- a/button.hpp +++ /dev/null @@ -1,25 +0,0 @@ -#ifndef BUTTON_HPP -#define BUTTON_HPP - -#include "widget.hpp" -#include <functional> - - -class Button : public Widget -{ - public: - Button(Application* parent, int x, int y, int szel, int mag, - std::string cimke, std::function<void()>); - - virtual void rajzol() const override; - virtual void kezel(genv::event ev) override; - - void action(); - - protected: - std::string _cimke; - std::function<void()> _f; - -}; - -#endif // BUTTON_HPP diff --git a/feladat.txt b/feladat.txt index 5a61e0c227fdfb7ebba4390d0ae4325e3df23cf0..76742c850b6ab9890f942195c55b91f91ca7366b 100644 --- a/feladat.txt +++ b/feladat.txt @@ -1 +1 @@ -9 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 5 3 0 0 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 \ No newline at end of file +9 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 5 3 0 0 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 diff --git a/feladat1.txt b/feladat1.txt new file mode 100644 index 0000000000000000000000000000000000000000..5a61e0c227fdfb7ebba4390d0ae4325e3df23cf0 --- /dev/null +++ b/feladat1.txt @@ -0,0 +1 @@ +9 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 5 3 0 0 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 \ No newline at end of file diff --git a/feladat2.txt b/feladat2.txt new file mode 100644 index 0000000000000000000000000000000000000000..184de548b64cdabcc6f527140eb422c2b93a48a2 --- /dev/null +++ b/feladat2.txt @@ -0,0 +1 @@ +0 1 4 7 0 6 0 0 0 0 0 0 5 0 3 6 0 0 0 3 6 4 2 0 0 1 9 0 0 1 0 7 0 2 0 3 3 0 0 1 4 0 0 6 7 0 0 0 3 6 2 0 5 4 0 0 0 2 0 4 0 0 5 2 7 5 9 0 1 4 0 6 4 8 3 0 5 0 9 0 0 \ No newline at end of file diff --git a/feladat3.txt b/feladat3.txt new file mode 100644 index 0000000000000000000000000000000000000000..460f63fb7ebbf79112c06f9f596466ca100960fe --- /dev/null +++ b/feladat3.txt @@ -0,0 +1 @@ +0 6 0 0 2 0 5 0 0 0 9 0 0 0 3 6 2 4 4 2 7 5 6 0 0 0 3 6 0 4 0 0 5 7 0 0 1 8 0 0 3 7 4 0 6 2 0 0 1 4 0 9 3 8 7 5 3 6 0 1 2 0 0 0 1 0 0 7 0 3 6 5 9 4 0 3 0 2 0 7 0 \ No newline at end of file diff --git a/gamemaster.cpp b/gamemaster.cpp index 379a6e977842f2cebebb563381ea68e525fbdbe1..8e41c64bfbf81736f3075cb4a61e00ce88f73251 100644 --- a/gamemaster.cpp +++ b/gamemaster.cpp @@ -10,9 +10,15 @@ GameMaster::GameMaster(Application* parent, std::string mo, std::string fe) : { _parent->register_gm(this); - _megoldas = fajl_beolvasas(_fajl_megoldas); - _feladat = fajl_beolvasas(_fajl_feladat); - _save = fajl_beolvasas(_fajl_save); + std::ifstream fajl("palyaszam.txt"); + if (!fajl.good()) + { + cout << "NEM JO A FAJL" << endl; + } + fajl >> _palyaszam; + fajl.close(); + + kezdo_jatek(); // megmondja hogy melyik indexek melyik nagy negyzethez tartoznak _negyzetek.resize(9); @@ -141,40 +147,68 @@ bool GameMaster::kesz() return valasz; } -void GameMaster::uj_jatek() +void GameMaster::kezdo_jatek() { - for (int i=0; i<_megoldas.size(); i++) + if (_palyaszam==1) { - _megoldas[i]=0; + _megoldas = fajl_beolvasas("megoldas1.txt"); + _feladat = fajl_beolvasas("feladat1.txt"); } - for (int i=0; i<17; i++) + if (_palyaszam==2) { - _megoldas[i] = rand()%9+1; - cout << i << " " <<_megoldas[i] << endl; + _megoldas = fajl_beolvasas("megoldas2.txt"); + _feladat = fajl_beolvasas("feladat2.txt"); + } - while (!szabalyos_e(i,_megoldas[i])) - { - _megoldas[i] = rand()%9+1; - cout << i << " " << _megoldas[i] << endl; - } - //fajl_kiiras("megoldas_generalo.txt",_megoldas); + if (_palyaszam==3) + { + _megoldas = fajl_beolvasas("megoldas3.txt"); + _feladat = fajl_beolvasas("feladat3.txt"); + } + + fajl_kiiras("megoldas.txt",_megoldas); + + fajl_kiiras("feladat.txt",_feladat); + + _save = fajl_beolvasas(_fajl_save); +} + +void GameMaster::uj_jatek() +{ + if (_palyaszam<3) + _palyaszam++; + else + _palyaszam=1; + + std::ofstream fajl("palyaszam.txt"); + fajl << _palyaszam; + fajl.close(); + + if (_palyaszam==1) + { + _megoldas = fajl_beolvasas("megoldas1.txt"); + _feladat = fajl_beolvasas("feladat1.txt"); } - for (int i=17; i<_megoldas.size(); i++) + if (_palyaszam==2) { - for (int j=1; j<=9; j++) - { - if (szabalyos_e(i,j)) - { - _megoldas[i]=j; - j = 9; - } - } - cout << i << " " << _megoldas[i] << endl; + _megoldas = fajl_beolvasas("megoldas2.txt"); + _feladat = fajl_beolvasas("feladat2.txt"); + } + + if (_palyaszam==3) + { + _megoldas = fajl_beolvasas("megoldas3.txt"); + _feladat = fajl_beolvasas("feladat3.txt"); } - fajl_kiiras("megoldas_generalo.txt",_megoldas); + fajl_kiiras("megoldas.txt",_megoldas); + + fajl_kiiras("feladat.txt",_feladat); + + _save = _feladat; + fajl_kiiras("save.txt",_save); } void GameMaster::save(int sorszam, int ertek) @@ -214,11 +248,6 @@ std::vector<int> GameMaster::fajl_beolvasas(std::string fajlnev) return v; } -void GameMaster::save_fajlba() -{ - fajl_kiiras(_fajl_save,_save); -} - void GameMaster::fajl_kiiras(std::string fajlnev,std::vector<int> v) const { std::ofstream fajl(fajlnev); @@ -229,3 +258,8 @@ void GameMaster::fajl_kiiras(std::string fajlnev,std::vector<int> v) const fajl << endl; fajl.close(); } + +void GameMaster::save_fajlba() const +{ + fajl_kiiras(_fajl_save,_save); +} diff --git a/gamemaster.hpp b/gamemaster.hpp index 37d84a035f75d952bde64ab1fdf4e79b84fd460b..2bc84b27daa5cc2725b5c37ba6f828a5d8293485 100644 --- a/gamemaster.hpp +++ b/gamemaster.hpp @@ -14,7 +14,7 @@ class GameMaster std::vector<int> fajl_beolvasas(std::string fajlnev); void fajl_kiiras(std::string fajlnev, std::vector<int> v) const; - void save_fajlba(); + void save_fajlba() const; std::vector<int> get_feladat(); std::vector<int> get_save(); @@ -27,12 +27,14 @@ class GameMaster virtual bool kesz(); virtual bool szabalyos_e(int,int); virtual void uj_jatek(); + virtual void kezdo_jatek(); protected: std::string _fajl_megoldas, _fajl_feladat, _fajl_save; std::vector<int> _megoldas, _feladat, _save; Application *_parent; std::vector<std::vector<int>> _negyzetek; + int _palyaszam; }; #endif // GAMEMASTER_HPP diff --git a/megoldas.txt b/megoldas.txt index e0e3317d77db8d668e716cfddae9b4c48e29ca9f..27ef7f0c4b9773327ceac2f277efd3eff73ba3d9 100644 --- a/megoldas.txt +++ b/megoldas.txt @@ -1 +1 @@ -9 8 5 6 2 1 4 7 3 3 7 6 5 4 9 8 2 1 2 4 1 7 3 8 5 6 9 8 6 7 9 5 4 1 3 2 5 3 4 2 1 7 9 8 6 1 9 2 8 6 3 7 5 4 4 5 3 1 7 2 6 9 8 6 2 9 4 8 5 3 1 7 7 1 8 3 9 6 2 4 5 \ No newline at end of file +9 8 5 6 2 1 4 7 3 3 7 6 5 4 9 8 2 1 2 4 1 7 3 8 5 6 9 8 6 7 9 5 4 1 3 2 5 3 4 2 1 7 9 8 6 1 9 2 8 6 3 7 5 4 4 5 3 1 7 2 6 9 8 6 2 9 4 8 5 3 1 7 7 1 8 3 9 6 2 4 5 diff --git a/megoldas1.txt b/megoldas1.txt new file mode 100644 index 0000000000000000000000000000000000000000..e0e3317d77db8d668e716cfddae9b4c48e29ca9f --- /dev/null +++ b/megoldas1.txt @@ -0,0 +1 @@ +9 8 5 6 2 1 4 7 3 3 7 6 5 4 9 8 2 1 2 4 1 7 3 8 5 6 9 8 6 7 9 5 4 1 3 2 5 3 4 2 1 7 9 8 6 1 9 2 8 6 3 7 5 4 4 5 3 1 7 2 6 9 8 6 2 9 4 8 5 3 1 7 7 1 8 3 9 6 2 4 5 \ No newline at end of file diff --git a/megoldas2.txt b/megoldas2.txt new file mode 100644 index 0000000000000000000000000000000000000000..91fb187a625d4fff2f2038efd3d072df83bd9f45 --- /dev/null +++ b/megoldas2.txt @@ -0,0 +1 @@ +8 1 4 7 9 6 5 3 2 9 2 7 5 1 3 6 4 8 5 3 6 4 2 8 7 1 9 6 4 1 8 7 5 2 9 3 3 5 2 1 4 9 8 6 7 7 9 8 3 6 2 1 5 4 1 6 9 2 8 4 3 7 5 2 7 5 9 3 1 4 8 6 4 8 3 6 5 7 9 2 1 \ No newline at end of file diff --git a/megoldas3.txt b/megoldas3.txt new file mode 100644 index 0000000000000000000000000000000000000000..e6c93dccb0f2ae2bc73944c916cb4c8f64bdc1c4 --- /dev/null +++ b/megoldas3.txt @@ -0,0 +1 @@ +3 6 1 4 2 9 5 8 7 5 9 8 7 1 3 6 2 4 4 2 7 5 6 8 1 9 3 6 3 4 8 9 5 7 1 2 1 8 9 2 3 7 4 5 6 2 7 5 1 4 6 9 3 8 7 5 3 6 8 1 2 4 9 8 1 2 9 7 4 3 6 5 9 4 6 3 5 2 8 7 1 \ No newline at end of file diff --git a/myapp.cpp b/myapp.cpp index 19dabe680ba337af81054aaf660061b79c240674..697bb4b94c7a4797615be0b771df74fb452b55a0 100644 --- a/myapp.cpp +++ b/myapp.cpp @@ -44,6 +44,20 @@ int MyApp::action(std::string id, genv::event ev, int focus) palya[i]->set_aura(false); } } + set<int> szabalytalan_set = _game->szabalytalanok(); + + for (int i=0; i<palya.size(); i++) + { + if (szabalytalan_set.find(i) != szabalytalan_set.end()) + { + palya[i]->set_szabalyos(false); + } + else + { + palya[i]->set_szabalyos(true); + } + } + palya[focus]->kezel(ev); } if (id=="key") @@ -92,6 +106,13 @@ int MyApp::action(std::string id, genv::event ev, int focus) } } + /*// csak arra volt, hogy teszteljem a palyak valtakozasat + if (ev.keycode==key_enter) + { + uj_palya(); + focus = action("start", ev, 0); + }*/ + if (ev.keycode >= 49 && ev.keycode <= 57) { palya[focus]->set_ertek(ev.keycode-48); @@ -113,8 +134,10 @@ int MyApp::action(std::string id, genv::event ev, int focus) if (_game->kesz()) /// UJ JATEK { - cout << "BEFEJEZTED OMG" << endl; - _replay_btn = new Button(this, 30,30,300,80,"uj jatek", [=](){uj_jatek();}); + // cout << "BEFEJEZTED" << endl; + + uj_palya(); + focus = action("start", ev, 0); } } @@ -172,7 +195,25 @@ int MyApp::action(std::string id, genv::event ev, int focus) return focus; } -void MyApp::uj_jatek() +void MyApp::uj_palya() { - cout << "megnyomtad a replayt" << endl; + _game->uj_jatek(); + + palya.clear(); + 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 + { + Index sorszam_index(j,i); + Field *f = new Field(this,i*78,j*78,78,sorszam,game_feladat[sorszam]); + palya.push_back(f); + if (game_feladat[sorszam] == 0) + { + palya[sorszam]->set_ertek(game_save[sorszam]); + } + } + } } diff --git a/myapp.hpp b/myapp.hpp index c56b8cd33000f17574acf09553883a2e8c8892c5..3cf2734349d11d68b8c9b9e2e420842c8d661a40 100644 --- a/myapp.hpp +++ b/myapp.hpp @@ -5,18 +5,16 @@ #include "widget.hpp" #include "field.hpp" #include "gamemaster.hpp" -#include "button.hpp" class MyApp : public Application { public: MyApp(int,int); int action(std::string,genv::event,int) override; - void uj_jatek(); + void uj_palya(); protected: std::vector<Field*> palya; - Button* _replay_btn; }; #endif // MYAPP_HPP diff --git a/palyaszam.txt b/palyaszam.txt new file mode 100644 index 0000000000000000000000000000000000000000..56a6051ca2b02b04ef92d5150c9ef600403cb1de --- /dev/null +++ b/palyaszam.txt @@ -0,0 +1 @@ +1 \ No newline at end of file diff --git a/save.txt b/save.txt index e49992eb27e4272f9a48e6a69a27308168181335..76742c850b6ab9890f942195c55b91f91ca7366b 100644 --- a/save.txt +++ b/save.txt @@ -1 +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 +9 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 5 3 0 0 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