Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
puzzleplayer
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
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
Floris
puzzleplayer
Commits
f90b4dda
Commit
f90b4dda
authored
4 months ago
by
Floris
Browse files
Options
Downloads
Patches
Plain Diff
update
parent
95f523a2
No related branches found
Branches containing commit
Tags
v1.32.3
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
PuzzlePlayer/Binary.cs
+8
-2
8 additions, 2 deletions
PuzzlePlayer/Binary.cs
PuzzlePlayer/PuzzleForm.cs
+19
-13
19 additions, 13 deletions
PuzzlePlayer/PuzzleForm.cs
with
27 additions
and
15 deletions
PuzzlePlayer/Binary.cs
+
8
−
2
View file @
f90b4dda
...
@@ -30,12 +30,13 @@ namespace PuzzlePlayer_Namespace
...
@@ -30,12 +30,13 @@ namespace PuzzlePlayer_Namespace
public
override
void
Draw
(
Graphics
gr
,
Rectangle
r
)
//draws board in rectangle R. warning: will stretch image unless FitBoard() is used for rectangle size
public
override
void
Draw
(
Graphics
gr
,
Rectangle
r
)
//draws board in rectangle R. warning: will stretch image unless FitBoard() is used for rectangle size
{
{
Size
tilesize
=
new
Size
(
r
.
Width
/
boardState
.
GetLength
(
0
),
r
.
Height
/
boardState
.
GetLength
(
1
));
Size
tilesize
=
new
Size
(
r
.
Width
/
boardState
.
GetLength
(
0
),
r
.
Height
/
boardState
.
GetLength
(
1
));
gr
.
FillRectangle
(
Brushes
.
Gainsboro
,
r
.
X
,
r
.
Y
,
tilesize
.
Width
*
boardState
.
GetLength
(
0
),
tilesize
.
Height
*
boardState
.
GetLength
(
1
));
Pen
border
=
new
Pen
(
Color
.
Black
,
2
);
gr
.
FillRectangle
(
Brushes
.
Beige
,
r
.
X
,
r
.
Y
,
tilesize
.
Width
*
boardState
.
GetLength
(
0
),
tilesize
.
Height
*
boardState
.
GetLength
(
1
));
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
);
i
++)
for
(
int
i
=
0
;
i
<
boardState
.
GetLength
(
0
);
i
++)
{
{
for
(
int
j
=
0
;
j
<
boardState
.
GetLength
(
1
);
j
++)
for
(
int
j
=
0
;
j
<
boardState
.
GetLength
(
1
);
j
++)
{
{
gr
.
DrawRectangle
(
Pens
.
Black
,
gr
.
DrawRectangle
(
Pens
.
LightGray
,
r
.
X
+
i
*
tilesize
.
Width
,
r
.
X
+
i
*
tilesize
.
Width
,
r
.
Y
+
j
*
tilesize
.
Height
,
r
.
Y
+
j
*
tilesize
.
Height
,
tilesize
.
Width
,
tilesize
.
Width
,
...
@@ -47,6 +48,11 @@ namespace PuzzlePlayer_Namespace
...
@@ -47,6 +48,11 @@ namespace PuzzlePlayer_Namespace
(
int
)(
r
.
Y
+
((
double
)
j
+
0.125
)
*
tilesize
.
Height
),
(
int
)(
r
.
Y
+
((
double
)
j
+
0.125
)
*
tilesize
.
Height
),
tilesize
.
Width
*
3
/
4
,
tilesize
.
Width
*
3
/
4
,
tilesize
.
Height
*
3
/
4
);
tilesize
.
Height
*
3
/
4
);
gr
.
DrawEllipse
(
border
,
(
int
)(
r
.
X
+
((
double
)
i
+
0.125
)
*
tilesize
.
Width
+
border
.
Width
/
2
),
(
int
)(
r
.
Y
+
((
double
)
j
+
0.125
)
*
tilesize
.
Height
+
border
.
Width
/
2
),
tilesize
.
Width
*
3
/
4
-
border
.
Width
,
tilesize
.
Height
*
3
/
4
-
border
.
Width
);
}
}
if
(
boardState
[
i
,
j
]
==
1
)
if
(
boardState
[
i
,
j
]
==
1
)
{
{
...
...
This diff is collapsed.
Click to expand it.
PuzzlePlayer/PuzzleForm.cs
+
19
−
13
View file @
f90b4dda
...
@@ -31,10 +31,11 @@ namespace PuzzlePlayer_Namespace
...
@@ -31,10 +31,11 @@ namespace PuzzlePlayer_Namespace
public
PuzzleForm
(
Board
b
=
null
,
Size
s
=
default
(
Size
))
//Takes Board and Size parameter and sets up the PuzzleForm window.
public
PuzzleForm
(
Board
b
=
null
,
Size
s
=
default
(
Size
))
//Takes Board and Size parameter and sets up the PuzzleForm window.
{
{
if
(
s
==
default
(
Size
))
s
=
new
Size
(
8
00
,
50
0
);
if
(
s
==
default
(
Size
))
s
=
new
Size
(
7
00
,
42
0
);
this
.
Size
=
s
;
this
.
Size
=
this
.
MinimumSize
=
s
;
this
.
WindowState
=
FormWindowState
.
Maximized
;
this
.
WindowState
=
FormWindowState
.
Maximized
;
this
.
BackColor
=
Color
.
Beige
;
this
.
BackColor
=
Color
.
DarkGreen
;
this
.
Text
=
"top text"
;
graphics
=
this
.
CreateGraphics
();
graphics
=
this
.
CreateGraphics
();
graphics
.
SmoothingMode
=
System
.
Drawing
.
Drawing2D
.
SmoothingMode
.
AntiAlias
;
graphics
.
SmoothingMode
=
System
.
Drawing
.
Drawing2D
.
SmoothingMode
.
AntiAlias
;
generatebutton
=
new
Button
();
generatebutton
=
new
Button
();
...
@@ -44,19 +45,17 @@ namespace PuzzlePlayer_Namespace
...
@@ -44,19 +45,17 @@ namespace PuzzlePlayer_Namespace
boardspace
=
new
Rectangle
(
220
,
30
,
400
,
400
);
boardspace
=
new
Rectangle
(
220
,
30
,
400
,
400
);
this
.
Paint
+=
(
object
o
,
PaintEventArgs
pea
)
=>
this
.
Paint
+=
(
object
o
,
PaintEventArgs
pea
)
=>
{
{
graphics
.
Clear
(
this
.
BackColor
);
board
.
Draw
(
graphics
,
boardspace
);
board
.
Draw
(
graphics
,
boardspace
);
//graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width -
40
0, this.Height - 100);
//graphics.FillRectangle(Brushes.LightCoral, 220, 30, this.Width -
38
0, this.Height - 100);
//graphics.FillRectangle(Brushes.DarkRed,
220, 30,
boardspace
.Width*Board.boardState.GetLength(0), boardspace.Height * Board.boardState.GetLength(1)
);
//graphics.FillRectangle(Brushes.DarkRed, boardspace);
};
};
this
.
Resize
+=
(
object
o
,
EventArgs
ea
)
=>
UpdateUI
();
this
.
Resize
+=
(
object
o
,
EventArgs
ea
)
=>
UpdateUI
();
Board
=
b
;
Board
=
b
;
CreateUI
();
CreateUI
();
UpdateUI
();
Board
.
boardState
[
1
,
1
]
=
1
;
Board
.
boardState
[
1
,
1
]
=
1
;
Board
.
boardState
[
2
,
2
]
=
0
;
Board
.
boardState
[
2
,
2
]
=
0
;
}
}
private
void
CreateUI
()
private
void
CreateUI
()
//sets up ui elements
{
{
void
CreateButton
(
Button
b
)
void
CreateButton
(
Button
b
)
{
{
...
@@ -87,26 +86,33 @@ namespace PuzzlePlayer_Namespace
...
@@ -87,26 +86,33 @@ namespace PuzzlePlayer_Namespace
Controls
.
Add
(
informationbox
);
Controls
.
Add
(
informationbox
);
informationbox
.
Multiline
=
true
;
informationbox
.
Multiline
=
true
;
informationbox
.
Size
=
new
Size
(
160
,
4
00
);
informationbox
.
Size
=
new
Size
(
160
,
3
00
);
informationbox
.
BackColor
=
Color
.
LightGray
;
informationbox
.
BackColor
=
Color
.
LightGray
;
informationbox
.
Text
=
board
.
description
;
informationbox
.
Text
=
board
.
description
;
informationbox
.
Font
=
new
Font
(
"Verdana"
,
10
);
UpdateUI
();
}
}
private
void
UpdateUI
()
private
void
UpdateUI
()
//resizes the boardspace rectangle and updates the rest of the ui around the new boardspace size
{
{
boardspace
.
Size
=
FitBoard
(
new
Size
(
Board
.
boardState
.
GetLength
(
0
),
Board
.
boardState
.
GetLength
(
1
)),
new
Size
(
this
.
Width
-
400
,
this
.
Height
-
100
),
8
);
graphics
.
Clear
(
this
.
BackColor
);
boardspace
.
Size
=
FitBoard
(
new
Size
(
Board
.
boardState
.
GetLength
(
0
),
Board
.
boardState
.
GetLength
(
1
)),
new
Size
(
this
.
Width
-
380
,
this
.
Height
-
100
),
8
);
generatebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
30
);
generatebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
30
);
hintbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
130
);
hintbutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
130
);
solvebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
230
);
solvebutton
.
Location
=
new
Point
(
boardspace
.
Right
+
30
,
230
);
informationbox
.
Location
=
new
Point
(
40
,
30
);
informationbox
.
Location
=
new
Point
(
40
,
30
);
this
.
Invalidate
();
this
.
Invalidate
();
}
}
public
static
Size
FitBoard
(
Size
gamesize
,
Size
maxboardsize
,
int
drawfactor
)
public
static
Size
FitBoard
(
Size
gamesize
,
Size
maxboardsize
,
int
drawfactor
)
//returns the largest rectangle smaller than MaxBoardSize that fits the given GameSize well
{
{
int
TileLength
=
Math
.
Min
(
maxboardsize
.
Width
/
gamesize
.
Width
,
maxboardsize
.
Height
/
gamesize
.
Height
)
/
drawfactor
*
drawfactor
;
int
TileLength
=
Math
.
Min
(
maxboardsize
.
Width
/
gamesize
.
Width
,
maxboardsize
.
Height
/
gamesize
.
Height
)
/
drawfactor
*
drawfactor
;
return
new
Size
(
gamesize
.
Width
*
TileLength
,
gamesize
.
Height
*
TileLength
);
return
new
Size
(
gamesize
.
Width
*
TileLength
,
gamesize
.
Height
*
TileLength
);
//After each of the divisions in this method, the value should be rounded down,
//After each of the divisions in this method, the value should be rounded down,
//as the end value cannot exceed the size given by maxboardsize.
//as the end value cannot exceed the size given by maxboardsize.
//however, C# rounds divisions of Int values down by default, so this does not have to be explicitly done.
//however, C# rounds divisions of Int values down by default, so this does not have to be explicitly done.
}
}
public
static
Point
GetTile
(
Point
p
)
{
return
p
;
}
}
}
}
}
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