From 86f09ccc319a5bb34550bb21f31d07bc15269e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Papp=20Benj=C3=A1min?= <papbe5@cortex.itk.ppke.hu> Date: Sun, 19 May 2024 09:43:52 +0200 Subject: [PATCH] =?UTF-8?q?eger=20iranyitas,=20mester=20l=C3=A9trehozva?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 5 +++-- mester.cpp | 21 +++++++++++++++++++++ mester.h | 20 ++++++++++++++++++++ palya.cpp | 19 +++++++++---------- palya.h | 12 ++++++++---- palyamezo.cpp | 10 ++++++++-- palyamezo.h | 6 ++++-- 7 files changed, 73 insertions(+), 20 deletions(-) create mode 100644 mester.cpp create mode 100644 mester.h diff --git a/main.cpp b/main.cpp index e3c00ae..9a5d6f5 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 0000000..d7e1d2f --- /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 0000000..62aeca9 --- /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 28ea398..363310f 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 198ef99..6bf74b3 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 b6bf45e..05d2efa 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 a2ea4f0..85c6abd 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 -- GitLab