109 lines
3.1 KiB
C#
109 lines
3.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace NonoGramme
|
|
{
|
|
internal class Line
|
|
{
|
|
private static Random rnd = new Random();
|
|
private Tile[] _data;
|
|
private int _length;
|
|
private List<int> _hints;
|
|
public Tile[] Data { get => _data; set => _data = value; }
|
|
public int Length { get => _length; set => _length = value; }
|
|
public List<int> Hints { get => _hints; set => _hints = value; }
|
|
|
|
public Line(Tile[] states)
|
|
{
|
|
//This method will create a new Line wich can then be edited
|
|
Data = states;
|
|
RecalculateHints();
|
|
}
|
|
public Line(int length)
|
|
{
|
|
//This method will just create the Line but totally empty
|
|
Length = length;
|
|
Data = new Tile[Length];
|
|
for (int i = 0; i < Length; i++)
|
|
{
|
|
Data[i] = new Tile();
|
|
}
|
|
|
|
RecalculateHints();
|
|
}
|
|
public string GetHorizontalHints()
|
|
{
|
|
string result = "";
|
|
int counter = 0;
|
|
foreach (int hint in Hints)
|
|
{
|
|
counter++;
|
|
if (counter != Hints.Count)
|
|
{
|
|
result += hint + ",";
|
|
}
|
|
else
|
|
{
|
|
result += hint;
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
public string GetVerticalHints()
|
|
{
|
|
string result = "";
|
|
foreach (int hint in Hints)
|
|
{
|
|
result += hint + Environment.NewLine;
|
|
}
|
|
return result;
|
|
}
|
|
public void Edit(int index, Tile.State state)
|
|
{
|
|
Data[index].CurrentState = state;
|
|
RecalculateHints();
|
|
}
|
|
public void RecalculateHints()
|
|
{
|
|
Hints = new List<int>();
|
|
bool previousTile = false;
|
|
bool currentTile = false;
|
|
int counter = 0;
|
|
for (int i = 0; i < Data.Length; i++)
|
|
{
|
|
switch (Data[i].CurrentState)
|
|
{
|
|
case Tile.State.Discovered:
|
|
case Tile.State.Empty:
|
|
case Tile.State.Full:
|
|
currentTile = false;
|
|
break;
|
|
case Tile.State.Undiscovered:
|
|
currentTile = true;
|
|
break;
|
|
}
|
|
if (currentTile)
|
|
{
|
|
counter++;
|
|
}
|
|
if (!currentTile && previousTile)
|
|
{
|
|
//We had a full segment that just finished
|
|
Hints.Add(counter);
|
|
counter = 0;
|
|
}
|
|
|
|
previousTile = currentTile;
|
|
}
|
|
if (currentTile)
|
|
{
|
|
//if the last tilke is full then we need to add it at the end
|
|
Hints.Add(counter);
|
|
}
|
|
}
|
|
}
|
|
}
|