Skip to content
Snippets Groups Projects
Commit 15bc8f4d authored by Ódor Boglárka's avatar Ódor Boglárka
Browse files

szinek

parent 7084933a
Branches main
No related tags found
No related merge requests found
......@@ -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);
}
......
......@@ -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) {
......
......@@ -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
......@@ -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;
}
......
......@@ -5,7 +5,7 @@
#include "application.hpp"
#include <functional>
class Application; // Forward declaration
class Application;
class Widget {
protected:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment