Skip to content
Snippets Groups Projects
Commit bae447fa authored by Monoki Dorina's avatar Monoki Dorina
Browse files

szol az onellentmondasert, szol ha vege a jateknak, replay meg nem mukodik

parent 16ade703
Branches
No related tags found
No related merge requests found
......@@ -54,7 +54,6 @@ class Application
protected:
std::vector<Widget*> widgets;
GameMaster *_game;
int _focus;
};
#endif // APPLICATION_HPP
#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();
}
#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
......@@ -80,8 +80,6 @@ void Field::rajzol() const
_y+(_mag-gout.cascent()-gout.cdescent())/2)
<< text(std::to_string(_ertek));
//gout << text(" ") << text(std::to_string(_aura));
}
}
......
......@@ -58,19 +58,27 @@ set<int> GameMaster::aura(int jelenlegi_int)
return s;
}
vector<int> GameMaster::szabalytalan(int jelenlegi_ertek, vector<vector<int>> aura_ertekek)
set<int> GameMaster::szabalytalanok()
{
vector<int> v;
set<int> s;
for (int i=0; i<aura_ertekek.size(); i++)
for (int i=0; i<_save.size(); i++)
{
std::set<int> aura_halmaz = aura(i);
for (int j=0; j<_save.size(); j++)
{
if (aura_ertekek[i][1] == jelenlegi_ertek)
if (aura_halmaz.find(j) != aura_halmaz.end())
{
v.push_back(aura_ertekek[i][0]);
if (_save[i] == _save[j] && _save[i]!=0)
{
s.insert(j);
//cout << i << " " << j << " " <<_save[i] << " " << _save[j] << endl;
}
}
}
}
return v;
return s;
}
int GameMaster::negyzet_szama(Index jelenlegi)
......@@ -104,6 +112,19 @@ int GameMaster::negyzet_szama(Index jelenlegi)
}
}
bool GameMaster::kesz()
{
bool valasz = true;
for (int i=0; i<_megoldas.size(); i++)
{
if (_megoldas[i] != _save[i])
{
valasz = false;
}
}
return valasz;
}
void GameMaster::save(int sorszam, int ertek)
{
_save[sorszam]=ertek;
......
......@@ -21,7 +21,8 @@ class GameMaster
virtual void save(int,int);
std::set<int> aura(int);
std::vector<int> szabalytalan(int,std::vector<std::vector<int>>);
std::set<int> szabalytalanok();
virtual bool kesz();
virtual int negyzet_szama(Index);
protected:
......
......@@ -95,56 +95,48 @@ 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);
_game->save(focus,palya[focus]->get_ertek());
set<int> szabalytalan_set = _game->szabalytalanok();
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())
if (szabalytalan_set.find(i) != szabalytalan_set.end())
{
aura_ertekek.push_back({i,palya[i]->get_ertek()});
palya[i]->set_szabalyos(false);
}
else
{
palya[i]->set_szabalyos(true);
}
}
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++)
if (_game->kesz()) /// UJ JATEK
{
palya[helytelenek[i]]->set_szabalyos(false);
cout << "BEFEJEZTED OMG" << endl;
_replay_btn = new Button(this, 30,30,300,80,"uj jatek", [=](){uj_jatek();});
}
}
_game->save(focus,palya[focus]->get_ertek());
}
if (ev.keycode==key_delete || ev.keycode==key_backspace)
{
palya[focus]->set_szabalyos(true);
palya[focus]->set_ertek(0);
_game->save(focus,palya[focus]->get_ertek());
set<int> szabalytalan_set = _game->szabalytalanok();
/*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())
if (szabalytalan_set.find(i) != szabalytalan_set.end())
{
aura_ertekek.push_back({i,palya[i]->get_ertek()});
palya[i]->set_szabalyos(false);
}
}
vector<int> helytelenek = _game->szabalytalan(palya[focus]->get_ertek(),aura_ertekek);
if (helytelenek.size() != 0)
{
for (int i=0; i<helytelenek.size(); i++)
else
{
palya[helytelenek[i]]->set_szabalyos(true);
palya[i]->set_szabalyos(true);
}
}
}*/
palya[focus]->set_ertek(0);
_game->save(focus,palya[focus]->get_ertek());
}
}
......@@ -179,3 +171,8 @@ int MyApp::action(std::string id, genv::event ev, int focus)
}
return focus;
}
void MyApp::uj_jatek()
{
cout << "megnyomtad a replayt" << endl;
}
......@@ -5,15 +5,18 @@
#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();
protected:
std::vector<Field*> palya;
Button* _replay_btn;
};
#endif // MYAPP_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment