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

application ujracsinalva, kattinthato egerrel

parent 8da4c928
Branches
No related tags found
No related merge requests found
......@@ -14,22 +14,9 @@ Application::Application(int szel, int mag)
void Application::event_loop()
{
Index focus(0,0);
event ev;
widgets[focus_index]->kezel(ev);
std::set<int> aura_halmaz = _game->aura(focus); // azert van itt is, hogy a megnyitaskor is rajzoljon aurat
for (int i=0; i<widgets.size(); i++)
{
if (aura_halmaz.find(i) != aura_halmaz.end())
{
action("aura",i,1);
}
else
{
action("aura",i,0);
}
}
int focus = action("start", ev, 0);
widgets[focus]->kezel(ev);
for (Widget *w : widgets)
{
......@@ -37,72 +24,23 @@ void Application::event_loop()
}
gout << refresh;
while(gin>>ev)
while(gin >> ev)
{
if (ev.type==ev_key)
if (ev.type==ev_mouse)
{
if (ev.keycode==key_up || ev.keycode==key_down ||
ev.keycode==key_left || ev.keycode==key_right)
{
widgets[focus_index]->unfocus();
if (ev.keycode==key_up)
{
if (focus.sor >0)
focus.sor -= 1;
}
else if (ev.keycode==key_down)
{
if (focus.sor <8)
focus.sor += 1;
}
else if (ev.keycode==key_left)
{
if (focus.oszlop >0)
focus.oszlop -= 1;
}
else if (ev.keycode==key_right)
{
if (focus.oszlop <8)
focus.oszlop += 1;
}
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
{
action("aura",i,0);
}
}
widgets[focus_index]->kezel(ev);
}
focus = action("mouse", ev, focus);
}
if (ev.keycode >= 49 && ev.keycode <= 57)
{
action("ertek",focus_index, ev.keycode-48);
}
if (ev.type==ev_key)
{
focus = action("key", ev, focus);
if (ev.keycode==key_delete || ev.keycode==key_backspace)
{
action("ertek",focus_index, 0);
}
}
for (Widget *w : widgets)
for (Widget* w : widgets)
{
w->rajzol();
}
gout << refresh;
_game->save_fajlba();
}
}
......
......@@ -25,6 +25,19 @@ struct Index
oszlop=0;
}
int sor,oszlop;
Index(int sorszam) : sor(sorszam/9), oszlop(sorszam%9)
{
if (sor>8)
sor=8;
else if (sor<0)
sor=0;
if (oszlop>8)
oszlop=8;
else if (oszlop<0)
oszlop=0;
}
};
class Application
......@@ -35,11 +48,12 @@ class Application
virtual void event_loop();
virtual void register_widget(Widget*);
virtual void register_gm(GameMaster*);
virtual void action(std::string,int,int) = 0;
virtual int action(std::string id, genv::event,int) = 0;
protected:
std::vector<Widget*> widgets;
GameMaster *_game;
int _focus;
};
#endif // APPLICATION_HPP
......@@ -28,8 +28,9 @@ GameMaster::GameMaster(Application* parent, std::string mo, std::string fe) :
}
set<int> GameMaster::aura(Index jelenlegi)
set<int> GameMaster::aura(int jelenlegi_int)
{
Index jelenlegi(jelenlegi_int);
set<int> s;
int negyzet=negyzet_szama(jelenlegi);
......
......@@ -20,7 +20,7 @@ class GameMaster
std::vector<int> get_save();
virtual void save(int,int);
std::set<int> aura(Index);
std::set<int> aura(int);
virtual int negyzet_szama(Index);
virtual bool szabalyos_e(int,std::set<int>);
......
#include "graphics.hpp"
#include "application.hpp"
#include "widget.hpp"
#include "field.hpp"
#include "gamemaster.hpp"
#include <vector>
#define sorszam_i 9*j+i
using namespace std;
class MyApp : public Application
{
public:
MyApp(int szel, int mag) : Application(szel,mag)
{
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,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]);
}
}
}
}
void action(std::string id, int sorszam, int ertek) override
{
if (id=="ertek")
{
palya[sorszam]->set_ertek(ertek);
game->save(sorszam,ertek);
}
if (id=="aura")
{
if (ertek==1)
palya[sorszam]->set_aura_true();
else if (ertek==0)
palya[sorszam]->set_aura_false();
}
}
protected:
vector<Field*> palya;
GameMaster* game;
};
#include "myapp.hpp"
int main()
{
......
myapp.cpp 0 → 100644
#include "myapp.hpp"
#define sorszam 9*sorszam_index.sor+sorszam_index.oszlop
#define focus_visszavaltas 9*focus_sorszam.sor+focus_sorszam.oszlop
using namespace std;
using namespace genv;
MyApp::MyApp(int szel, int mag) : Application(szel,mag)
{
_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
{
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]);
}
}
}
}
int MyApp::action(std::string id, genv::event ev, int focus)
{
if (id=="start")
{
std::set<int> aura_halmaz = _game->aura(focus); // azert van itt is, hogy a megnyitaskor is rajzoljon aurat
for (int i=0; i<palya.size(); i++)
{
if (aura_halmaz.find(i) != aura_halmaz.end())
{
palya[i]->set_aura_true();
}
else
{
palya[i]->set_aura_false();
}
}
}
if (id=="key")
{
if (ev.keycode==key_up || ev.keycode==key_down ||
ev.keycode==key_left || ev.keycode==key_right)
{
palya[focus]->unfocus();
Index focus_sorszam(focus);
if (ev.keycode==key_up)
{
if (focus_sorszam.sor >0)
focus_sorszam.sor -= 1;
}
else if (ev.keycode==key_down)
{
if (focus_sorszam.sor <8)
focus_sorszam.sor += 1;
}
else if (ev.keycode==key_left)
{
if (focus_sorszam.oszlop >0)
focus_sorszam.oszlop -= 1;
}
else if (ev.keycode==key_right)
{
if (focus_sorszam.oszlop <8)
focus_sorszam.oszlop += 1;
}
focus = focus_visszavaltas;
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())
{
palya[i]->set_aura_true();
}
else
{
palya[i]->set_aura_false();
}
}
}
if (ev.keycode >= 49 && ev.keycode <= 57)
{
palya[focus]->set_ertek(ev.keycode-48);
}
if (ev.keycode==key_delete || ev.keycode==key_backspace)
{
palya[focus]->set_ertek(0);
}
_game->save(focus,palya[focus]->get_ertek());
}
if (id=="mouse")
{
if (ev.button==btn_left)
{
for (size_t i=0; i<palya.size(); i++)
{
if (palya[i]->belul(ev.pos_x,ev.pos_y))
{
palya[focus]->unfocus();
focus=i;
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())
{
palya[i]->set_aura_true();
}
else
{
palya[i]->set_aura_false();
}
}
}
}
return focus;
}
#ifndef MYAPP_HPP
#define MYAPP_HPP
#include "application.hpp"
#include "widget.hpp"
#include "field.hpp"
#include "gamemaster.hpp"
#include <vector>
class MyApp : public Application
{
public:
MyApp(int,int);
int action(std::string,genv::event,int) override;
protected:
std::vector<Field*> palya;
};
#endif // MYAPP_HPP
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment