Added drawing of the hints

This commit is contained in:
2022-10-13 07:39:44 +02:00
parent 76daa4782d
commit 9b255c8ed9
5 changed files with 247 additions and 23 deletions
+129 -9
View File
@@ -4,6 +4,10 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace NonoGramme
{
internal class Grid
@@ -28,6 +32,110 @@ namespace NonoGramme
VerticalLines = new Line[size.Width];
Populate();
}
public Grid(string filePath)
{
ImportFromFile(filePath);
}
public void ImportFromFile(string filePath)
{
//GridSize = size;
//HorizontalLines = new Line[size.Height];
//VerticalLines = new Line[size.Width];
string fileContent = File.ReadAllText(filePath);
string catalogue = "";
string title = "";
string author = "";
string copyright = "";
string license = "";
Size size = new Size(0,0);
List<int>[] rows;
List<int>[] columns;
string rawData = "";
//It would be smart to have a Header Struct to store all those metadatas
Regex rx = new Regex(@"^catalogue ""(?<content>.+)""",RegexOptions.Multiline| RegexOptions.IgnoreCase);
MatchCollection matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
catalogue = matches[0].Groups[1].Value;
}
rx = new Regex(@"^title ""(?<content>.+)""", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
title = matches[0].Groups[1].Value;
}
rx = new Regex(@"^by ""(?<content>.+)""", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
author = matches[0].Groups[1].Value;
}
rx = new Regex(@"^copyright ""(?<content>.+)""", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
copyright = matches[0].Groups[1].Value;
}
rx = new Regex(@"^license (?<content>.+)$", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
license = matches[0].Groups[1].Value;
}
rx = new Regex(@"^height (?<height>[0-9]+)\nwidth (?<width>[0-9]+)", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
size =new Size(Convert.ToInt32(matches[0].Groups["width"].Value), Convert.ToInt32(matches[0].Groups["height"].Value));
}
string TEST = "";
rows = new List<int>[size.Height];
rx = new Regex(@"^rows\n(?<row>[0-9,]+\r?\n)+", RegexOptions.Multiline);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
/*
foreach (GroupCollection group in matches[0].Groups)
{
TEST += @"\n"+group[0].Value;
}
*/
}
columns = new List<int>[size.Height];
rx = new Regex(@"^columns\n([0-9,]+\r?\n)+", RegexOptions.Multiline);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
//TODO
}
rx = new Regex(@"^goal ""([0-1]+)""", RegexOptions.Multiline | RegexOptions.IgnoreCase);
matches = rx.Matches(fileContent);
if (matches.Count > 0 && matches[0].Groups.Count > 0)
{
rawData = matches[0].Groups[1].Value;
}
MessageBox.Show(rawData);
/*
for ()
{
}
*/
}
private void Populate()
{
Random rnd = new Random();
@@ -66,17 +174,29 @@ namespace NonoGramme
Size actualSize = new Size(UI.Width - offset.X, UI.Height - offset.Y);
Size blocSize = new Size(actualSize.Width/GridSize.Width,actualSize.Height/GridSize.Height);
//Drawing the rows Text
//TODO
//Drawing the columns Text
//TODO
//Drawing the grid
using (Graphics g = Graphics.FromImage(UI))
{
//Drawing the rows Text
int rowCount = 0;
string hints = "";
for (int i = 0; i < HorizontalLines.Count(); i++)
{
hints = HorizontalLines[i].GetHorizontalHints();
g.DrawString(hints,new Font("Arial",16),Brushes.Black,new Point(0,offset.Y + rowCount*blocSize.Height));
rowCount++;
}
//Drawing the columns Text
int columnCount = 0;
hints = "";
for (int i = 0; i < VerticalLines.Count(); i++)
{
hints = VerticalLines[i].GetVerticalHints();
g.DrawString(hints, new Font("Arial", 16), Brushes.Black, new Point(offset.Y + columnCount * blocSize.Width, 0));
columnCount++;
}
//Drawing the grid
int row = 0;
foreach (Line line in HorizontalLines)
{