Added partial file import and Hints calculation

This commit is contained in:
2022-10-13 10:08:13 +02:00
parent 9b255c8ed9
commit d96a793344
3 changed files with 87 additions and 18 deletions
+37 -9
View File
@@ -16,7 +16,8 @@ namespace NonoGramme
public int Length { get => _length; set => _length = value; }
public List<int> Hints { get => _hints; set => _hints = value; }
public Line(Tile[] states) {
public Line(Tile[] states)
{
//This method will create a new Line wich can then be edited
Data = states;
RecalculateHints();
@@ -26,9 +27,9 @@ namespace NonoGramme
//This method will just create the Line but totally empty
Length = length;
Data = new Tile[Length];
for (int i = 0; i< Length; i++)
for (int i = 0; i < Length; i++)
{
Data[i] = new Tile();
Data[i] = new Tile();
}
RecalculateHints();
@@ -52,7 +53,7 @@ namespace NonoGramme
return result;
}
public string GetVerticalHints()
{
{
string result = "";
foreach (int hint in Hints)
{
@@ -67,13 +68,40 @@ namespace NonoGramme
}
public void RecalculateHints()
{
//This will have to be done, for now its just a placeholder
//TO REMOVE !!
Hints = new List<int>();
int count = rnd.Next(1, Data.Count()-1);
for (int i = 0;i < count;i++)
bool previousTile = false;
bool currentTile = false;
int counter = 0;
for (int i = 0; i < Data.Length; i++)
{
Hints.Add(rnd.Next(1, Data.Count()-1));
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);
}
}
}