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

player létrehozva, már lehet ábrákat nyomni a pályára

parent 8f2c211c
No related branches found
No related tags found
No related merge requests found
#include "palya.h" #include "palya.h"
using namespace std;
using namespace genv; using namespace genv;
int main() int main()
......
#include "mester.h" #include "mester.h"
#include "palya.h" #include "palya.h"
#include "palyamezo.h" #include "palyamezo.h"
#include "player.h"
#include <iostream> #include <iostream>
using namespace genv; using namespace genv;
using namespace std;
Mester::Mester(Palya* _p) : p(_p) {} Mester::Mester()
{
player1 = new Player("Player1", 0);
player2 = new Player("Player2", 1);
aktiv = player1;
}
void Mester::PlayerChange(){
if(aktiv == player1) {aktiv = player2;}
else
if(aktiv == player2) {aktiv = player1;}
}
void Mester::iranyitas(Palyamezo* f, event ev) { void Mester::iranyitas(Palyamezo* f, event ev) {
if(f->hozzaer(ev) && !f->filled && !f->chosen){ if(f->hozzaer(ev) && !f->get_filled() && !f->get_chosen()){
f->chosen_draw(); f->chosen_draw();
f->set_chosen(); f->set_chosen();
} }
if(!f->hozzaer(ev) && !f->filled && f->chosen){ if(!f->hozzaer(ev) && !f->get_filled() && f->get_chosen()){
f->draw(); f->draw();
f->reset_chosen(); f->reset_chosen();
} }
if(f->select(ev) && !f->filled) if(f->select(ev) && !f->get_filled()){
lepes = true; cout << aktiv->get_name() << endl;
f->mark(aktiv->get_sorszam());
f->fillin();
PlayerChange();
}
} }
void Mester::turn() {}
Mester::~Mester() {} Mester::~Mester() {}
...@@ -4,16 +4,19 @@ ...@@ -4,16 +4,19 @@
class Palya; class Palya;
class Palyamezo; class Palyamezo;
class Player;
class Mester class Mester
{ {
Palya* p; Palya* p;
genv::event ev; genv::event ev;
bool lepes = false; Player* player1;
Player* player2;
Player* aktiv;
public: public:
Mester(Palya* _p); Mester();
void iranyitas(Palyamezo* f, genv::event ev); void iranyitas(Palyamezo* f, genv::event ev);
void turn(); void PlayerChange();
~Mester(); ~Mester();
}; };
......
...@@ -16,7 +16,7 @@ Palya::Palya() ...@@ -16,7 +16,7 @@ Palya::Palya()
negyzet->draw(); negyzet->draw();
} }
} }
mesztor = new Mester(this); mesztor = new Mester();
} }
void Palya::jatek(event ev){ void Palya::jatek(event ev){
......
...@@ -10,9 +10,9 @@ class Palya ...@@ -10,9 +10,9 @@ class Palya
{ {
const int XX = 1000; const int XX = 1000;
const int YY = 1000; const int YY = 1000;
std::vector<Palyamezo*> palyaterulet;
public: public:
Palya(); Palya();
std::vector<Palyamezo*> palyaterulet;
Mester* mesztor; Mester* mesztor;
void jatek(genv::event ev); void jatek(genv::event ev);
~Palya(); ~Palya();
......
#include "palyamezo.h" #include "palyamezo.h"
#define red 235,25,25
#define blue 0,175,255
using namespace genv; using namespace genv;
...@@ -17,6 +19,12 @@ void Palyamezo::chosen_draw(){ ...@@ -17,6 +19,12 @@ void Palyamezo::chosen_draw(){
gout << move_to(x+1,y+1) << color(t,t,t) << box(w-2,h-2); gout << move_to(x+1,y+1) << color(t,t,t) << box(w-2,h-2);
} }
bool Palyamezo::get_filled() {return filled;}
void Palyamezo::fillin() {filled = true;}
bool Palyamezo::get_chosen() {return chosen;}
void Palyamezo::set_chosen(){ void Palyamezo::set_chosen(){
if(!chosen) if(!chosen)
chosen = true; chosen = true;
...@@ -27,4 +35,12 @@ void Palyamezo::reset_chosen(){ ...@@ -27,4 +35,12 @@ void Palyamezo::reset_chosen(){
chosen = false; chosen = false;
} }
void Palyamezo::mark(int id){
gout << move_to(x+1,y+1) << color(0,0,0) << box(w-2,h-2);
if(id == 0)
gout << move_to(x+5,y+5) << color(red) << line(0,30) << line(30,0) << line(0,-30) << line(-30,0);
if(id == 1)
gout << move_to(x+5,y+35) << color(blue) << line(30,0) << line_to(x+w/2,y+5) << line_to(x+5,y+35);
}
Palyamezo::~Palyamezo() {} Palyamezo::~Palyamezo() {}
...@@ -6,15 +6,19 @@ class Palyamezo : public Widget ...@@ -6,15 +6,19 @@ class Palyamezo : public Widget
{ {
int index_m; int index_m;
int index_n; int index_n;
bool filled = false;
bool chosen = false;
public: public:
Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n); Palyamezo(Palya* _p, int _x, int _y, int _w, int _h, int _m, int _n);
~Palyamezo(); ~Palyamezo();
void draw() override; void draw() override;
void chosen_draw(); void chosen_draw();
bool filled = false; bool get_filled();
bool chosen = false; void fillin();
bool get_chosen();
void set_chosen(); void set_chosen();
void reset_chosen(); void reset_chosen();
void mark(int id);
}; };
#endif // PALYAMEZO_H #endif // PALYAMEZO_H
#include "player.h"
using namespace std;
Player::Player(string _name, int _sorszam) : name(_name), sorszam(_sorszam) {}
string Player::get_name() {return name;}
int Player::get_pontszam() {return pontszam;}
int Player::get_sorszam() {return sorszam;}
Player::~Player() {}
player.h 0 → 100644
#ifndef PLAYER_H
#define PLAYER_H
#include <string>
class Player
{
std::string name;
int pontszam = 0;
int sorszam;
public:
Player(std::string _nev, int _sorszam);
std::string get_name();
int get_pontszam();
int get_sorszam();
~Player();
};
#endif // PLAYER_H
...@@ -12,8 +12,10 @@ bool Widget::hozzaer(event ev){ ...@@ -12,8 +12,10 @@ bool Widget::hozzaer(event ev){
} }
bool Widget::select(event ev){ bool Widget::select(event ev){
if(hozzaer(ev) && ev.button==btn_left) if(ev.type == ev_mouse){
return true; if(hozzaer(ev) && ev.button==btn_left)
if(!hozzaer(ev) && ev.button==btn_left) return true;
return false; else
return false;
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment