Skip to content
Snippets Groups Projects
Commit b8b82252 authored by Papp Benjámin's avatar Papp Benjámin
Browse files

pálya; teszt az egyes indexek felismerésére

parent 4f7fc96d
Branches
No related tags found
No related merge requests found
main.cpp 0 → 100644
#include "palya.h"
using namespace std;
using namespace genv;
int main()
{
Palya* tictac = new Palya();
event ev;
while (gin >> ev && ev.keycode!=key_escape)
{
tictac->proba(ev);
gout << refresh;
}
}
//Papp Benjamin (I8KQEC)
#include <iostream>
#include "palya.h"
using namespace std;
using namespace genv;
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);
}
}
for(Widget* r : palyaterulet)
r->draw();
}
void Palya::proba(event ev)
{
for(Palyamezo* r : palyaterulet){
if(r->hozzaer(ev))
cout << r->index_m << " - " << r->index_n << endl;
}
}
Palya::~Palya() {}
palya.h 0 → 100644
#ifndef PALYA_H
#define PALYA_H
#include <vector>
#include "palyamezo.h"
class Palya
{
std::vector<Palyamezo*> palyaterulet;
public:
const int XX = 1000;
const int YY = 1000;
Palya();
void proba(genv:: event ev);
~Palya();
};
#endif // PALYA_H
#include "palyamezo.h"
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);
}
#ifndef PALYAMEZO_H
#define PALYAMEZO_H
#include "widget.h"
class Palyamezo : public Widget
{
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;
};
#endif // PALYAMEZO_H
#include "widget.h"
using namespace genv;
Widget::Widget(Palya* _p, int _x, int _y, int _w, int _h) : p(_p), x(_x), y(_y), w(_w), h(_h){}
bool Widget::hozzaer(event ev)
{
if(ev.pos_x > x && ev.pos_x < x+w && ev.pos_y < y+h && ev.pos_y > y)
return true;
else
return false;
}
bool Widget::select(event ev)
{
if(hozzaer(ev) && ev.button==btn_left)
return true;
if(!hozzaer(ev) && ev.button==btn_left)
return false;
}
widget.h 0 → 100644
#ifndef WIDGET_H
#define WIDGET_H
#include "graphics.hpp"
class Palya;
class Widget{
protected:
int x,y,w,h;
Palya* p;
public:
Widget(Palya* _p, int _x, int _y, int _w, int _h);
bool hozzaer(genv::event ev);
bool select(genv::event ev);
virtual void draw() = 0;
};
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment