From 7cf79a24273af4d6ce1956ca123f95fcb068448a Mon Sep 17 00:00:00 2001 From: "fodor.agoston" <fodor.agoston@hallgato.ppke.hu> Date: Sun, 19 May 2024 22:20:18 +0200 Subject: [PATCH] =?UTF-8?q?v=C3=A9gleges=20verzi=C3=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application.cpp | 78 ++++++++++++++++++++++++++++++++++++++++++------- application.hpp | 4 ++- menu.cpp | 2 -- spinbox.cpp | 11 +++++-- 4 files changed, 80 insertions(+), 15 deletions(-) diff --git a/application.cpp b/application.cpp index f0fea5b..9d48dda 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 e0b7189..b269078 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 fe0e07d..7856a68 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 812a326..f270908 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) -- GitLab