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

5. prednaska

parent fdf33081
......@@ -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!");
}
......
......@@ -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)
......
......@@ -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);
}
}
}
......
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