Skip to content
Snippets Groups Projects
Commit 7cf79a24 authored by Fodor Ágoston's avatar Fodor Ágoston
Browse files

végleges verzió

parent 7c2c4c60
No related branches found
No related tags found
No related merge requests found
...@@ -42,8 +42,36 @@ void Application :: board(int diffi) ...@@ -42,8 +42,36 @@ void Application :: board(int diffi)
{0, 0, 0, 0, 8, 0, 0, 7, 9} {0, 0, 0, 0, 8, 0, 0, 7, 9}
}; };
} }
if(diffi == 2)
{
board = {
{3, 0, 0, 0, 9, 0, 8, 2, 0},
{0, 1, 0, 6, 0, 0, 0, 0, 0},
{0, 0, 0, 4, 3, 0, 0, 7, 6},
{0, 9, 1, 0, 0, 0, 6, 4, 0},
{0, 0, 0, 0, 2, 0, 0, 0, 8},
{6, 0, 8, 9, 0, 0, 0, 0, 0},
{7, 0, 6, 3, 0, 9, 2, 5, 4},
{1, 2, 3, 5, 0, 8, 0, 6, 9},
{0, 4, 0, 2, 0, 7, 0, 0, 0}
};
}
if(diffi == 3)
{
board = {
{0, 0, 0, 0, 0, 0, 0, 0, 9},
{9, 4, 0, 0, 0, 0, 8, 3, 0},
{0, 0, 0, 9, 0, 0, 6, 0, 2},
{0, 1, 0, 7, 0, 0, 0, 9, 0},
{0, 0, 0, 0, 0, 2, 0, 5, 0},
{0, 0, 7, 0, 0, 6, 0, 0, 0},
{0, 0, 0, 0, 0, 1, 0, 0, 0},
{5, 8, 1, 0, 2, 0, 0, 0, 0},
{0, 6, 0, 0, 0, 8, 4, 0, 0}
};
}
board_values = board;
for (int i = 0; i < 9; ++i) for (int i = 0; i < 9; ++i)
{ {
...@@ -68,35 +96,45 @@ void Application :: board(int diffi) ...@@ -68,35 +96,45 @@ void Application :: board(int diffi)
} }
} }
bool Application::check_board() {
for (int i = 0; i < 9; ++i) {
for (int j = 0; j < 9; ++j) {
if (widgets2[i][j]->getter() != board_values[i][j]) {
return false;
}
}
}
return true;
}
void Application::event_loop() void Application::event_loop()
{ {
Menu m;
int wrongi = -1; int wrongi = -1;
event ev;
int focus = -1; int focus = -1;
while (m.diffret() == 0 and gin >> ev)
{
event ev;
while (m.diffret() == 0 and gin >> ev)
{
m.draw(); m.draw();
m.handle(ev); m.handle(ev);
gout << refresh; gout << refresh;
if(ev.type == ev_key and ev.keycode == key_escape)
{
break;
}
} }
board(m.diffret()); board(m.diffret());
while(gin >> ev) while(gin >> ev)
{ {
if (ev.type == ev_mouse && ev.button==btn_left) if (ev.type == ev_mouse && ev.button==btn_left)
{ {
for (size_t i=0; i<widgets.size(); i++) for (size_t i=0; i<widgets.size(); i++)
...@@ -190,6 +228,26 @@ void Application::event_loop() ...@@ -190,6 +228,26 @@ void Application::event_loop()
{ {
break; break;
} }
int rowsum = 0;
int colsum = 0;
for (int i = 0; i < 9; ++i)
{
for (int j = 0; j < 9; ++j)
{
rowsum += widgets2[i][j]->getter();
}
}
for (int j = 0; j < 9; ++j)
{
for (int i = 0; i < 9; ++i)
{
colsum += widgets2[i][j]->getter();
}
}
if(colsum == 9*45 and rowsum == 9*45 and wrongi == -1)
{
break;
}
gout << refresh; gout << refresh;
......
...@@ -19,7 +19,7 @@ public: ...@@ -19,7 +19,7 @@ public:
virtual void event_loop(); virtual void event_loop();
virtual void registerWidget(Widget*); virtual void registerWidget(Widget*);
void ellenoriz(std::vector<Widget> v); void ellenoriz(std::vector<Widget> v);
bool check_board();
void board(int ); void board(int );
...@@ -29,6 +29,8 @@ public: ...@@ -29,6 +29,8 @@ public:
protected: protected:
std::vector<Widget*> widgets; std::vector<Widget*> widgets;
std::vector<std::vector<SpinBox*>> widgets2; std::vector<std::vector<SpinBox*>> widgets2;
Menu m;
std::vector<std::vector<int>> board_values;
}; };
......
...@@ -37,8 +37,6 @@ void Menu::handle(genv::event ev) { ...@@ -37,8 +37,6 @@ void Menu::handle(genv::event ev) {
{ {
diffnum = 3; diffnum = 3;
} }
} }
} }
......
...@@ -22,6 +22,7 @@ void SpinBox::draw() ...@@ -22,6 +22,7 @@ void SpinBox::draw()
gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2); gout << move_to(_x +2*_sizey + 1, _y + 1) << color(0,0,0) << box(_sizey - 2, _sizey -2);
int text_width = gout.twidth(to_string(_num)); int text_width = gout.twidth(to_string(_num));
int text_height = gout.cascent() + gout.cdescent(); int text_height = gout.cascent() + gout.cdescent();
...@@ -93,8 +94,14 @@ void SpinBox::handle(event ev) ...@@ -93,8 +94,14 @@ void SpinBox::handle(event ev)
_isselected = false; _isselected = false;
} }
} }
if(_isselected and ev.button == btn_wheeldown and _num >= _min + 1)
{
_num -= 1;
}
if(_isselected and ev.button == btn_wheelup and _num <= _max - 1)
{
_num += 1;
}
} }
else if(ev.type == ev_key) else if(ev.type == ev_key)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment