Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
bead3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ódor Boglárka
bead3
Commits
15bc8f4d
Commit
15bc8f4d
authored
1 year ago
by
Ódor Boglárka
Browse files
Options
Downloads
Patches
Plain Diff
szinek
parent
7084933a
Branches
main
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
board_widget.cpp
+13
-8
13 additions, 8 deletions
board_widget.cpp
jatek_mester.cpp
+3
-3
3 additions, 3 deletions
jatek_mester.cpp
jatek_mester.hpp
+1
-1
1 addition, 1 deletion
jatek_mester.hpp
main.cpp
+2
-3
2 additions, 3 deletions
main.cpp
widgets.hpp
+1
-1
1 addition, 1 deletion
widgets.hpp
with
20 additions
and
16 deletions
board_widget.cpp
+
13
−
8
View file @
15bc8f4d
...
...
@@ -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
(
25
5
,
25
5
,
2
55
)
<<
box
(
CELL_SIZE
,
CELL_SIZE
);
gout
<<
move_to
(
x
,
y
)
<<
color
(
25
0
,
7
5
,
2
41
)
<<
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
);
}
...
...
This diff is collapsed.
Click to expand it.
jatek_mester.cpp
+
3
−
3
View file @
15bc8f4d
...
...
@@ -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
)
{
...
...
This diff is collapsed.
Click to expand it.
jatek_mester.hpp
+
1
−
1
View file @
15bc8f4d
...
...
@@ -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
This diff is collapsed.
Click to expand it.
main.cpp
+
2
−
3
View file @
15bc8f4d
...
...
@@ -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
;
}
...
...
This diff is collapsed.
Click to expand it.
widgets.hpp
+
1
−
1
View file @
15bc8f4d
...
...
@@ -5,7 +5,7 @@
#include
"application.hpp"
#include
<functional>
class
Application
;
// Forward declaration
class
Application
;
class
Widget
{
protected:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment