diff --git a/application.cpp b/application.cpp index f0fea5bf6a3641762ac025851b4cc5f22cb4109f..9d48dda82ab0448c876da5d7541d4ff59841a71b 100644 --- a/application.cpp +++ b/application.cpp @@ -42,8 +42,36 @@ void Application :: board(int diffi) {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) { @@ -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() { - Menu m; + int wrongi = -1; - event ev; int focus = -1; - while (m.diffret() == 0 and gin >> ev) - { + event ev; + while (m.diffret() == 0 and gin >> ev) + { m.draw(); m.handle(ev); gout << refresh; - - if(ev.type == ev_key and ev.keycode == key_escape) - { - break; - } } + board(m.diffret()); while(gin >> ev) { + + + if (ev.type == ev_mouse && ev.button==btn_left) { for (size_t i=0; i<widgets.size(); i++) @@ -190,6 +228,26 @@ void Application::event_loop() { 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; diff --git a/application.hpp b/application.hpp index e0b71899c4b0c5c4a7de273727ba7b2e538ffb69..b2690788c530fd705b9f6dc28491d67bb06acf83 100644 --- a/application.hpp +++ b/application.hpp @@ -19,7 +19,7 @@ public: virtual void event_loop(); virtual void registerWidget(Widget*); void ellenoriz(std::vector<Widget> v); - + bool check_board(); void board(int ); @@ -29,6 +29,8 @@ public: protected: std::vector<Widget*> widgets; std::vector<std::vector<SpinBox*>> widgets2; + Menu m; + std::vector<std::vector<int>> board_values; }; diff --git a/menu.cpp b/menu.cpp index fe0e07d19734fac08c5ac64abd125d41cb39ad8b..7856a68c28df34e224cd8ea37a694bc179ddd4a2 100644 --- a/menu.cpp +++ b/menu.cpp @@ -37,8 +37,6 @@ void Menu::handle(genv::event ev) { { diffnum = 3; } - - } } diff --git a/spinbox.cpp b/spinbox.cpp index 812a326c9ffbf9cff97c174e49a63ba176cdc4ce..f270908fd59b7fc20f0c33f1f7d2cba44c36834d 100644 --- a/spinbox.cpp +++ b/spinbox.cpp @@ -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); + int text_width = gout.twidth(to_string(_num)); int text_height = gout.cascent() + gout.cdescent(); @@ -93,8 +94,14 @@ void SpinBox::handle(event ev) _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)