diff --git a/main.cpp b/main.cpp index e3c00aefde04b1e49521406226cf4a4b2b7fb934..9a5d6f5e3d1731a99a5d8848a52f1e3b9f67bc18 100644 --- a/main.cpp +++ b/main.cpp @@ -5,12 +5,13 @@ using namespace genv; int main() { + event ev; + Palya* tictac = new Palya(); - event ev; while (gin >> ev && ev.keycode!=key_escape) { - tictac->proba(ev); + tictac->jatek(ev); gout << refresh; } } diff --git a/mester.cpp b/mester.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d7e1d2f9dc091ac1d2e39d4acb8359b81651c638 --- /dev/null +++ b/mester.cpp @@ -0,0 +1,21 @@ +#include "mester.h" +#include "palya.h" +#include "palyamezo.h" +#include <iostream> + +using namespace genv; + +Mester::Mester(Palya* _p) : p(_p) {} + +void Mester::iranyitas(Palyamezo* f, event ev) { + if(f->hozzaer(ev) && !f->filled) + f->chosen_draw(); + if(!f->hozzaer(ev) && !f->filled) + f->draw(); + if(f->select(ev) && !f->filled) + lepes = true; +} + +void Mester::turn() {} + +Mester::~Mester() {} diff --git a/mester.h b/mester.h new file mode 100644 index 0000000000000000000000000000000000000000..62aeca9ac91f85cd5dd9b5c4a40c5de85b6bd834 --- /dev/null +++ b/mester.h @@ -0,0 +1,20 @@ +#ifndef MESTER_H +#define MESTER_H +#include "graphics.hpp" + +class Palya; +class Palyamezo; + +class Mester +{ + Palya* p; + genv::event ev; + bool lepes = false; +public: + Mester(Palya* _p); + void iranyitas(Palyamezo* f, genv::event ev); + void turn(); + ~Mester(); +}; + +#endif // MESTER_H diff --git a/palya.cpp b/palya.cpp index 28ea3984db23d7fe8a2b929c3d55d8f566fc396e..363310f7a06811e710754081b03e82517d6f8737 100644 --- a/palya.cpp +++ b/palya.cpp @@ -1,5 +1,7 @@ #include <iostream> #include "palya.h" +#include "palyamezo.h" +#include "mester.h" using namespace std; using namespace genv; @@ -9,20 +11,17 @@ Palya::Palya() gout.open(XX,YY); for(int i = 0; i<20; i++){ for(int j = 0; j<20; j++){ - Palyamezo* proba = new Palyamezo(this, 100+(i*40), 100+(j*40), 40, 40, i, j); - palyaterulet.push_back(proba); + Palyamezo* negyzet = new Palyamezo(this, 100+(i*40), 100+(j*40), 40, 40, i, j); + palyaterulet.push_back(negyzet); + negyzet->draw(); } } - for(Widget* r : palyaterulet) - r->draw(); + mesztor = new Mester(this); } -void Palya::proba(event ev) -{ - for(Palyamezo* r : palyaterulet){ - if(r->hozzaer(ev)) - cout << r->index_m << " - " << r->index_n << endl; - } +void Palya::jatek(event ev){ + for(Palyamezo* negyzet : palyaterulet) + mesztor->iranyitas(negyzet, ev); } Palya::~Palya() {} diff --git a/palya.h b/palya.h index 198ef9964ac3c5f99186753391f27bc8747a37d5..6bf74b3ffb9339914471b72cb6531c1eb3c0bb80 100644 --- a/palya.h +++ b/palya.h @@ -1,16 +1,20 @@ #ifndef PALYA_H #define PALYA_H #include <vector> -#include "palyamezo.h" +#include "graphics.hpp" + +class Mester; +class Palyamezo; class Palya { - std::vector<Palyamezo*> palyaterulet; -public: const int XX = 1000; const int YY = 1000; +public: Palya(); - void proba(genv:: event ev); + std::vector<Palyamezo*> palyaterulet; + Mester* mesztor; + void jatek(genv::event ev); ~Palya(); }; diff --git a/palyamezo.cpp b/palyamezo.cpp index b6bf45ec7bbc8195c3910d9b96802fc1e9c89333..05d2efa139f39190fcc263179f68a8c5a579b2a2 100644 --- a/palyamezo.cpp +++ b/palyamezo.cpp @@ -5,11 +5,17 @@ using namespace genv; Palyamezo::Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n) : Widget(_p, _x, _y, _w, _h), index_m(_m), index_n(_n) {} -Palyamezo::~Palyamezo() {} - void Palyamezo::draw(){ int t = 255; gout << move_to(x,y) << color(t,t,t) << box(w,h); t = 0; gout << move_to(x+1,y+1) << color(t,t,t) << box(w-2,h-2); } + +void Palyamezo::chosen_draw() +{ + int t = 175; + gout << move_to(x+1,y+1) << color(t,t,t) << box(w-2,h-2); +} + +Palyamezo::~Palyamezo() {} diff --git a/palyamezo.h b/palyamezo.h index a2ea4f0fd18df2fe16d15db6969b060bdaefdb81..85c6abddf394e2fee5d960de5e6881d9836ad976 100644 --- a/palyamezo.h +++ b/palyamezo.h @@ -4,12 +4,14 @@ class Palyamezo : public Widget { + int index_m; + int index_n; public: Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n); ~Palyamezo(); - int index_m; - int index_n; void draw() override; + void chosen_draw(); + bool filled = false; }; #endif // PALYAMEZO_H