Commit 1af34f37 authored by doc. Ing. Jaroslav Porubän PhD.'s avatar doc. Ing. Jaroslav Porubän PhD.
Browse files

3. prednaska

parent 054c7cc3
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\NPuzzleCore\NPuzzleCore.csproj" />
</ItemGroup>
</Project>
using System;
using NPuzzle.Core;
namespace ConsoleUi.App
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Field field;
}
}
}
......@@ -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
......
......@@ -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(Int32.Parse(line));
_field.Move(int.Parse(line));
}
catch (FormatException)
{
......
using System;
using NPuzzle.Core;
using NPuzzleCore.Core;
namespace NPuzzle
{
......
......@@ -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;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment