From 15bc8f4d125f1c415508f4909564e3851bfadc6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93dor=20Bogl=C3=A1rka?= <odobo@cortex.itk.ppke.hu> Date: Sun, 19 May 2024 20:23:06 +0200 Subject: [PATCH] szinek --- board_widget.cpp | 21 +++++++++++++-------- jatek_mester.cpp | 6 +++--- jatek_mester.hpp | 2 +- main.cpp | 5 ++--- widgets.hpp | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/board_widget.cpp b/board_widget.cpp index c7f35a1..258fc0e 100644 --- a/board_widget.cpp +++ b/board_widget.cpp @@ -2,39 +2,44 @@ #include "graphics.hpp" #include <iostream> +///betu �s vonalszin: 252, 232, 252 +///hatterszin: 250, 75, 241 +///helytelen: 61, 0, 58 + + using namespace genv; BoardWidget::BoardWidget(Application* parent, JatekMester* mester, int& selected_row, int& selected_col, int x, int y, int sx, int sy) : Widget(parent, x, y, sx, sy), mester(mester), selected_row(selected_row), selected_col(selected_col), BOARD_SIZE(9), CELL_SIZE(sx / BOARD_SIZE) {} void BoardWidget::draw() const { - // Draw cells and numbers + for (int i = 0; i < BOARD_SIZE; ++i) { for (int j = 0; j < BOARD_SIZE; ++j) { int x = _x + j * CELL_SIZE; int y = _y + i * CELL_SIZE; - gout << move_to(x, y) << color(255, 255, 255) << box(CELL_SIZE, CELL_SIZE); + gout << move_to(x, y) << color(250, 75, 241) << box(CELL_SIZE, CELL_SIZE); int value = mester->get_value(i, j); if (value != 0) { if (!mester->is_cell_valid(i, j)) { - gout << color(255, 0, 0); // Piros ha helytelen + gout << color(61, 0, 58); } else { - gout << color(0, 0, 0); // Fekete ha helyes + gout << color(252, 232, 252); } gout << move_to(x + CELL_SIZE / 3, y + CELL_SIZE / 1.5) << text(std::to_string(value)); } } } - // Draw grid lines + for (int i = 0; i <= BOARD_SIZE; ++i) { - int line_thickness = (i % 3 == 0) ? 3 : 1; // Thicker lines for block boundaries - gout << move_to(_x + i * CELL_SIZE, _y) << color(0, 0, 0); + int line_thickness = (i % 3 == 0) ? 3 : 1; + gout << move_to(_x + i * CELL_SIZE, _y) << color(252, 232, 252); for (int t = 0; t < line_thickness; ++t) { gout << move_to(_x + i * CELL_SIZE + t, _y) << line(0, _size_y); } - gout << move_to(_x, _y + i * CELL_SIZE) << color(0, 0, 0); + gout << move_to(_x, _y + i * CELL_SIZE) << color(252, 232, 252); for (int t = 0; t < line_thickness; ++t) { gout << move_to(_x, _y + i * CELL_SIZE + t) << line(_size_x, 0); } diff --git a/jatek_mester.cpp b/jatek_mester.cpp index 8bde953..f8b52a9 100644 --- a/jatek_mester.cpp +++ b/jatek_mester.cpp @@ -7,21 +7,21 @@ JatekMester::JatekMester() : board(9, std::vector<int>(9, 0)), original_board(9, std::vector<int>(9, 0)) {} bool JatekMester::is_valid_move(int number, int row, int col) const { - // Ellenőrizze a sorban + for (int j = 0; j < 9; ++j) { if (j != col && board[row][j] == number) { return false; } } - // Ellenőrizze az oszlopban + for (int i = 0; i < 9; ++i) { if (i != row && board[i][col] == number) { return false; } } - // Ellenőrizze a 3x3-as blokkban + int block_start_row = row - row % 3; int block_start_col = col - col % 3; for (int i = block_start_row; i < block_start_row + 3; ++i) { diff --git a/jatek_mester.hpp b/jatek_mester.hpp index 684db5b..fcda66c 100644 --- a/jatek_mester.hpp +++ b/jatek_mester.hpp @@ -16,7 +16,7 @@ public: void update_value(int row, int col, int value); int get_value(int row, int col) const; bool load_from_file(const std::string& filename); - bool is_cell_valid(int row, int col) const; // �j f�ggv�ny + bool is_cell_valid(int row, int col) const; }; #endif // JATEK_MESTER_HPP diff --git a/main.cpp b/main.cpp index 15562af..b563b75 100644 --- a/main.cpp +++ b/main.cpp @@ -5,12 +5,11 @@ #include "jatek_mester.hpp" - int main() { Application app(600, 600); JatekMester mester; - if (!mester.load_from_file("sudoku_easy.txt")) { - std::cerr << "Failed to load Sudoku board from file.\n"; + if (!mester.load_from_file("sudoku_medium.txt")) { + std::cerr << "Nem sikerult a file olvasasa.\n"; return 1; } diff --git a/widgets.hpp b/widgets.hpp index ca81c16..b399fc9 100644 --- a/widgets.hpp +++ b/widgets.hpp @@ -5,7 +5,7 @@ #include "application.hpp" #include <functional> -class Application; // Forward declaration +class Application; class Widget { protected: -- GitLab