Skip to content
Snippets Groups Projects
Commit cc3b9186 authored by Horváth Ádám's avatar Horváth Ádám
Browse files

lehet végleges

parent ac661019
No related branches found
No related tags found
No related merge requests found
#include "application.hpp"
#include "checkbox.hpp"
using namespace genv;
Application::Application(int boardSize)
{
gout.open(boardSize * 40, boardSize * 40); // Minden négyzet mérete 40x40 pixel
for (int i = 0; i < boardSize; i++)
{
for (int j = 0; j < boardSize; j++)
{
widgets.push_back(new CheckBox(this, j * 40, i * 40, 40, 40));
}
}
}
void Application::gameover(int sz)
{
game = false;
//gout << move_to(0, 0) << color(0, 0, 0) << box(800, 800);
gout << color(0, 0, 0) << move_to(100,300)<< box(800, 800);
if (sz == 0)
{
gout << move_to(100, 300) << color(255, 255, 255) << text(" Game over!\n Döntetlen! Jatek bezarasa: ESC,\n Uj jatek inditasa: space-t.") << refresh;
}
else if (sz % 2 == 0)
{
gout <<move_to(0,0)<<color(0,0,0) <<box(1000,1000)<< move_to(100, 300) << color(255, 255, 255) << text(" Game over!\n X nyert! Jatek bezarasa: ESC,\n Uj jatek inditasa: space-t.") << refresh;
}
else
{
gout << move_to(100, 300) << color(255, 255, 255) << text(" Game over!\n O nyert! Jatek bezarasa: ESC,\n Uj jatek inditasa: space-t.") << refresh;
}
}
bool Application::checker(int focus, int index)
{
if ("first" == "first")
{
int counter = 0;
int valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt++;
}
valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt--;
}
if (counter >= 6)
{
return true;
}
}
if ("second" == "second")
{
int counter = 0;
int valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt + 15;
}
valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt - 15;
}
if (counter >= 6)
{
return true;
}
}
if ("third" == "third")
{
int counter = 0;
int valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt + 16;
}
valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt - 16;
}
if (counter >= 6)
{
return true;
}
}
if ("fourth" == "fourth")
{
int counter = 0;
int valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt + 14;
}
valt = focus;
while (widgets[valt]->value_sz() != 0 && widgets[valt]->value_sz() % 2 == index % 2)
{
counter++;
valt = valt - 14;
}
if (counter >= 6)
{
return true;
}
}
return false;
}
void Application::event_loop() {
event ev;
int focus = -1;
int sz = 0;
while(gin >> ev)
{
if (ev.type == ev_key && ev.keycode==key_escape)
{
break;
}
if (ev.type == ev_key && ev.keycode==key_space && game == false)
{
for (Widget * w : widgets)
{
w->value(0);
}
game = true;
}
if (ev.type == ev_mouse && ev.button == btn_left)
{
for (size_t i = 0; i < widgets.size(); i++)
{
if (widgets[i]->is_selected(ev.pos_x, ev.pos_y))
focus = i;
}
}
if (focus!=-1) {
widgets[focus]->handle(ev);
if (widgets[focus]->is_checked() && widgets[focus]->value_sz() == 0)
{
sz++;
widgets[focus]->value(sz);
}
}
if (game)
{
for (Widget * w : widgets)
{
w->draw();
}
}
if (focus!=-1)
{
if (checker(focus, widgets[focus]->value_sz()))
{
gameover(widgets[focus]->value_sz());
}
}
if (sz == 225)
{
gameover(0);
}
gout << refresh;
}
}
void Application::registerWidget(Widget * widget)
{
widgets.push_back(widget);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment