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
+6 -2
View File
@@ -25,7 +25,7 @@ namespace NonoGramme
private void NewGame()
{
nonogramme1.NewRandomGame(new Size(5, 5));
nonogramme1.Refresh();
RefreshUi();
}
private void Form1_Load(object sender, EventArgs e)
@@ -47,9 +47,12 @@ namespace NonoGramme
{
nonogramme1.Size = new Size(ClientSize.Width - UI_BORDER, ClientSize.Width);
}
RefreshUi();
}
private void RefreshUi()
{
nonogramme1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
FolderBrowserDialog dialog = new FolderBrowserDialog();
@@ -80,6 +83,7 @@ namespace NonoGramme
{
selectedNonoGram = selectedFile;
nonogramme1.LoadNewGame(selectedNonoGram);
RefreshUi();
}
}
}
+44 -7
View File
@@ -14,6 +14,7 @@ namespace NonoGramme
{
private readonly Color DEFAULT_FULL_COLOR = Color.Black;
private readonly Color DEFAULT_EMPTY_COLOR = Color.LightGray;
private readonly Color DEBUG_UNDISCOVERED_COLOR = Color.DarkOliveGreen;
private readonly Color DEFAULT_BORDER_COLOR = Color.Pink;
private readonly Color DEFAULT_ERROR_COLOR = Color.Purple;
@@ -127,14 +128,37 @@ namespace NonoGramme
}
MessageBox.Show(rawData);
//MessageBox.Show(rawData);
if (rawData.Length != size.Width * size.Height)
MessageBox.Show("The file contains conflicting datas");
/*
for ()
//Filling the class with infos
GridSize = size;
HorizontalLines = new Line[GridSize.Height];
VerticalLines = new Line[GridSize.Width];
for (int y = 0; y < GridSize.Height; y++)
{
HorizontalLines[y] = new Line(GridSize.Width);
for (int x = 0; x < GridSize.Width; x++)
{
if (y == 0)
{
VerticalLines[x] = new Line(GridSize.Height);
}
*/
Tile.State tileState = Tile.State.Empty;
int flatIndex = y * GridSize.Width + x;
if (rawData[flatIndex] == 1)
{
tileState = Tile.State.Undiscovered;
}
HorizontalLines[y].Edit(x,tileState);
VerticalLines[x].Edit(y,tileState);
}
}
MessageBox.Show("File imported Successfully");
}
private void Populate()
{
@@ -157,7 +181,7 @@ namespace NonoGramme
state = Tile.State.Empty;
break;
case 3:
state = Tile.State.Full;
state = Tile.State.Undiscovered;
break;
default:
state = Tile.State.Empty;
@@ -169,8 +193,21 @@ namespace NonoGramme
}
Console.WriteLine("Coucou");
}
public void RefreshGrid()
{
foreach (Line line in HorizontalLines)
{
line.RecalculateHints();
}
foreach (Line line in VerticalLines)
{
line.RecalculateHints();
}
}
public Bitmap Draw(Bitmap UI,Point offset)
{
RefreshGrid();
Size actualSize = new Size(UI.Width - offset.X, UI.Height - offset.Y);
Size blocSize = new Size(actualSize.Width/GridSize.Width,actualSize.Height/GridSize.Height);
@@ -216,7 +253,7 @@ namespace NonoGramme
g.FillRectangle(new SolidBrush(DEFAULT_EMPTY_COLOR), new Rectangle(position, blocSize));
break;
case Tile.State.Undiscovered:
g.FillRectangle(new SolidBrush(DEFAULT_FULL_COLOR), new Rectangle(position, blocSize));
g.FillRectangle(new SolidBrush(DEBUG_UNDISCOVERED_COLOR), new Rectangle(position, blocSize));
break;
default:
g.FillRectangle(new SolidBrush(DEFAULT_ERROR_COLOR), new Rectangle(position, blocSize));
+35 -7
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,7 +27,7 @@ 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();
}
@@ -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);
}
}
}