Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
doc. Ing. Jaroslav Porubän PhD.
NPuzzle2021
Commits
7086895b
Commit
7086895b
authored
Mar 18, 2021
by
doc. Ing. Jaroslav Porubän PhD.
Browse files
5. prednaska
parent
fdf33081
Changes
3
Hide whitespace changes
Inline
Side-by-side
NPuzzleConsole/ConsoleUI.cs
View file @
7086895b
...
...
@@ -16,22 +16,25 @@ namespace NPuzzle.ConsoleUI
public
ConsoleUI
(
Field
field
)
{
_field
=
field
;
_field
.
OnFieldChange
+=
PrintField
;
}
public
void
Play
()
{
PrintTopScores
();
PrintField
();
do
{
PrintField
();
//
PrintField();
ProcessInput
();
}
while
(!
_field
.
IsSolved
());
_scoreService
.
AddScore
(
new
Score
{
Player
=
Environment
.
UserName
,
Points
=
_field
.
GetScore
(),
PlayedAt
=
DateTime
.
Now
});
PrintField
();
//
PrintField();
Console
.
WriteLine
(
"Game solved!"
);
}
...
...
NPuzzleCore/Core/Field.cs
View file @
7086895b
...
...
@@ -6,8 +6,13 @@ using NPuzzleCore.Core;
namespace
NPuzzle.Core
{
public
delegate
void
OnFieldChange
();
public
class
Field
{
//public event Action OnFieldChange;
public
event
OnFieldChange
OnFieldChange
;
private
readonly
Tile
[,]
_tiles
;
public
int
RowCount
{
get
;
}
...
...
@@ -24,7 +29,7 @@ namespace NPuzzle.Core
ColumnCount
=
columnCount
;
_tiles
=
new
Tile
[
rowCount
,
columnCount
];
Initialize
();
//
Shuffle();
Shuffle
();
startTime
=
DateTime
.
Now
;
}
...
...
@@ -85,6 +90,9 @@ namespace NPuzzle.Core
else
if
(
_emptyTileCoordinate
.
Row
<
RowCount
-
1
&&
_tiles
[
_emptyTileCoordinate
.
Row
+
1
,
_emptyTileCoordinate
.
Column
].
Value
==
tile
)
ExchangeWithEmpty
(
_emptyTileCoordinate
.
Row
+
1
,
_emptyTileCoordinate
.
Column
);
if
(
OnFieldChange
!=
null
)
OnFieldChange
();
}
private
void
ExchangeWithEmpty
(
int
row
,
int
column
)
...
...
NPuzzleCore/Service/ScoreServiceFile.cs
View file @
7086895b
...
...
@@ -49,7 +49,7 @@ namespace NPuzzleCore.Service
using
(
var
fs
=
File
.
OpenRead
(
FileName
))
{
var
bf
=
new
BinaryFormatter
();
_scores
=
(
List
<
Score
>)
bf
.
Deserialize
(
fs
);
_scores
=
(
List
<
Score
>)
bf
.
Deserialize
(
fs
);
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment