Skip to content
Snippets Groups Projects
Commit 2e746543 authored by Borostyán József Bálint's avatar Borostyán József Bálint :flag_al:
Browse files

Upload New File

parent 14aaa5e1
No related branches found
No related tags found
No related merge requests found
#include "jatekter.hpp"
#include "graphics.hpp"
using namespace genv;
JatekTer::JatekTer(int x_, int y_, int cs, JatekMester& jm)
: Widget(x_, y_, cs * jm.get(0, 0), cs * 6), jatek(jm), cellsize(cs) {}
void JatekTer::draw() const {
for (int r = 0; r < 6; ++r) {
for (int c = 0; c < 7; ++c) {
int px = x + c * cellsize;
int py = y + r * cellsize;
gout << color(0, 0, 255) << move_to(px, py) << box(cellsize, cellsize);
gout << color(0, 0, 0) << move_to(px + 2, py + 2) << box(cellsize - 4, cellsize - 4);
int val = jatek.get(r, c);
if (val == 1) gout << color(255, 0, 0);
else if (val == 2) gout << color(255, 255, 0);
else continue;
int cx = px + cellsize / 2;
int cy = py + cellsize / 2;
int r = cellsize / 2 - 5;
for (int dy = -r; dy <= r; ++dy)
for (int dx = -r; dx <= r; ++dx)
if (dx*dx + dy*dy <= r*r)
gout << move_to(cx + dx, cy + dy) << dot;
}
}
int winner = jatek.getWinner();
// nyertes kiiras
if (winner == 1) {
gout << move_to(50, 50) << color(255, 255, 255) << text("Piros nyert!");
}
else if (winner == 2) {
gout << move_to(50, 50) << color(255, 255, 255) << text("Sarga nyert!");
}
// dontetlen ellenorzes
else {
bool full = true;
for (int sor = 0; sor < 6; ++sor) {
for (int oszlop = 0; oszlop < 7; ++oszlop) {
if (jatek.get(sor, oszlop) == 0) {
full = false;
}
}
}
if (full) {
gout << move_to(50, 50) << color(255, 255, 255) << text("Dontetlen!");
}
}
}
void JatekTer::handle(event ev) {
if (ev.type == ev_mouse && ev.button == btn_left) {
int oszlop = (ev.pos_x - x) / cellsize;
if (jatek.ellenoriz() == 0) {
jatek.lepes(oszlop);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment