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
1af34f37
Commit
1af34f37
authored
Mar 06, 2021
by
doc. Ing. Jaroslav Porubän PhD.
Browse files
3. prednaska
parent
054c7cc3
Changes
6
Hide whitespace changes
Inline
Side-by-side
ConsoleApp1/ConsoleApp1.csproj
0 → 100644
View file @
1af34f37
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NPuzzleCore\NPuzzleCore.csproj" />
</ItemGroup>
</Project>
ConsoleApp1/Program.cs
0 → 100644
View file @
1af34f37
using
System
;
using
NPuzzle.Core
;
namespace
ConsoleUi.App
{
class
Program
{
static
void
Main
(
string
[]
args
)
{
Console
.
WriteLine
(
"Hello World!"
);
Field
field
;
}
}
}
NPuzzle2021.sln
View file @
1af34f37
...
...
@@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31005.135
MinimumVisualStudioVersion = 10.0.40219.1
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "NPuzzleCore", "NPuzzleCore\NPuzzleCore.csproj", "{B811769D-99DE-4E7E-9C33-4ABF157E78AB}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "NPuzzleCore", "NPuzzleCore\NPuzzleCore.csproj", "{B811769D-99DE-4E7E-9C33-4ABF157E78AB}"
EndProject
Project("{
FAE04EC0-301F-11D3-BF4B-00C04F79EFBC
}") = "NPuzzleConsole", "NPuzzleConsole\NPuzzleConsole.csproj", "{202AE2BB-A1CD-42F1-8ABD-4BF8F865A1BB}"
Project("{
9A19103F-16F7-4668-BE54-9A1E7A4F7556
}") = "NPuzzleConsole", "NPuzzleConsole\NPuzzleConsole.csproj", "{202AE2BB-A1CD-42F1-8ABD-4BF8F865A1BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
NPuzzleConsole/ConsoleUI.cs
View file @
1af34f37
...
...
@@ -49,10 +49,14 @@ namespace NPuzzle.ConsoleUI
private
void
ProcessInput
()
{
Console
.
Write
(
"Enter command: "
);
var
line
=
Console
.
ReadLine
();
var
line
=
Console
.
ReadLine
().
ToUpper
();
if
(
"X"
==
line
)
Environment
.
Exit
(
0
);
try
{
_field
.
Move
(
I
nt
32
.
Parse
(
line
));
_field
.
Move
(
i
nt
.
Parse
(
line
));
}
catch
(
FormatException
)
{
...
...
NPuzzleConsole/Program.cs
View file @
1af34f37
using
System
;
using
NPuzzle.Core
;
using
NPuzzleCore.Core
;
namespace
NPuzzle
{
...
...
NPuzzleCore/Core/Field.cs
View file @
1af34f37
...
...
@@ -18,9 +18,10 @@ namespace NPuzzle.Core
public
Field
(
int
rowCount
,
int
columnCount
)
{
RowCount
=
rowCount
;
ColumnCount
=
columnCount
;
ColumnCount
=
columnCount
;
_tiles
=
new
Tile
[
rowCount
,
columnCount
];
Initialize
();
Shuffle
();
}
public
Tile
GetTile
(
int
row
,
int
column
)
...
...
@@ -53,6 +54,19 @@ namespace NPuzzle.Core
_emptyTileCoordinate
=
new
Coordinate
{
Row
=
RowCount
-
1
,
Column
=
ColumnCount
-
1
};
}
private
void
Shuffle
()
{
var
random
=
new
Random
();
for
(
var
i
=
0
;
i
<
100
*
RowCount
*
ColumnCount
;
i
++)
{
Move
(
random
.
Next
(
RowCount
*
ColumnCount
-
1
)
+
1
);
}
}
/// <summary>
/// Moves a tile.
/// </summary>
/// <param name="tile">tile to move</param>
public
void
Move
(
int
tile
)
{
if
(
_emptyTileCoordinate
.
Column
>
0
&&
...
...
@@ -77,6 +91,10 @@ namespace NPuzzle.Core
_emptyTileCoordinate
.
Column
=
column
;
}
/// <summary>
///
/// </summary>
/// <returns>true if the field is solved</returns>
public
bool
IsSolved
()
{
var
value
=
1
;
...
...
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