I created 10 x 10 TextBoxes and the user should input the words into the relevant TextBoxes for the position of the words. And I save everything into a textfile like this:
Then on WPF side , I read the textfile and populate the TextBoxes in a panel but the problem is that the crossword puzzle has down and across hints that lead you to the answer and each hint will have a number to indicate which is which. However I can't think of a way to link the number's puzzle number to the hints down and across number. This is how it looks like now:
Notice the numbers (I edited them in paint to visualize what I want) beside the across and down, I need that numbers to be displayed.
In my database, I stored the location of the file in a table, and the hints and answer in another table like this:
And this is the hints (across and down) and answer:
I am using Entity framework lambda expressions to retrieve the across and down.
Appreciate any help on this to link the assign the numbers to Across and Down from the puzzle.
This is my code to display the puzzle :
protected void Across()
{
IList<ModelSQL.puzzlecontent> lstAcross = daoPuzzleContent.GetAcross();
foreach (ModelSQL.puzzlecontent lista in lstAcross)
{
Label tbA = new Label();
tbA.Content = lista.Hint;
tbA.Width = Double.NaN;
tbA.BorderBrush = Brushes.CadetBlue;
tbA.BorderThickness = new Thickness(2);
stackPanel1.Width = Double.NaN;
stackPanel1.Children.Add(tbA);
words.Add(lista.Answer);
}
}
protected void AddPuzzle()
{
// foldername of the txt file.
// using (StreamReader reader = File.OpenText((@daoWordPuzzle.GetfileURL())))
string[] fileData = File.ReadAllLines(@"C:\Users\apr13mpsip\Desktop\OneOrganizer\OneOrganizer\WordPuzzle\educational.txt");
string[] lineValues;
int row = 0;
int col;
int hint = 1;
string[][] rowcol = new string[fileData.Length][];
foreach (string line in fileData)
{
lineValues = line.Split(new string[] { "," }, StringSplitOptions.None);
rowcol[row] = new string[lineValues.Length];
col = 0;
foreach (string value in lineValues)
{
rowcol[row][col] = value;
col++;
}
row++;
}
for (int i = 0; i < rowcol.GetLength(0) ; i++)
{
for (int j = 0; j < rowcol[i].GetLength(0) ; j++)
{
int iadd = i+1 < rowcol.GetLength(0) ? i+1 : 100;
int iminus = i-1 >= 0 ? i-1 : 100;
int jadd = j+1 < rowcol.GetLength(0) ? j+1 : 100;
int jminus = j-1 >= 0 ? j-1 : 100;
var self = rowcol[i][j]; // current value
var top = iminus == 100 ? "" : rowcol[iminus][j];
var bottom = iadd == 100 ? "" : rowcol[iadd][j];
var left = jminus == 100 ? "" : rowcol[i][jminus];
var right = jadd == 100 ? "" : rowcol[i][jadd];
//ACROSS HORIZONTAL
if (
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left))
)
{
wordAcross = "";
for (int k = 0; k < 10; k++)
{
wordAcross += rowcol[i][k];
if (k == 9)
{
puzzlewordAcross.Add(wordAcross);
// print hello and live
}
}
}
//DOWN VERTICAL
if (
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(left))
)
{
wordDown = "";
for (int k = 0; k < 10; k++)
{
wordDown += rowcol[k][j];
if (k == 9)
{
puzzlewordDown.Add(wordDown);
// print holy and leducated
}
}
}
//Check Top , Left , Bottom , Right value.
if (
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && !String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && !String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && String.IsNullOrEmpty(right) && !String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left)) ||
(!String.IsNullOrEmpty(self) && String.IsNullOrEmpty(top) && !String.IsNullOrEmpty(right) && String.IsNullOrEmpty(bottom) && String.IsNullOrEmpty(left))
)
{
TextBox tbox = new TextBox();
tbox.Height = 50;
tbox.Width = 50;
tbox.Text = hint.ToString();
wrapPanel1.Children.Add(tbox);
tbox.GotFocus += (source, e) =>
{
if (!string.IsNullOrEmpty(tbox.Text))
{
string Str = tbox.Text.Trim();
double Num;
bool isNum = double.TryParse(Str, out Num);
if (isNum)
tbox.Text = "";
}
else
{
tbox.Text = "";
}
};
hint++;
}
else
{
TextBox tbox2 = new TextBox();
tbox2.Height = 50;
tbox2.Width = 50;
if (String.IsNullOrEmpty(self))
{
tbox2.Background = Brushes.Black;
tbox2.Focusable = false;
}
wrapPanel1.Children.Add(tbox2);
}// end of top bottom left right.
}
}
} // End of AddPuzzle()
Code to display Across and Down :
protected void Down()
{
IList<ModelSQL.puzzlecontent> lstDown = daoPuzzleContent.GetDown();
foreach (ModelSQL.puzzlecontent listd in lstDown)
{
Label tbD = new Label();
tbD.Content = listd.Hint;
tbD.Width = Double.NaN;
tbD.BorderBrush = Brushes.CadetBlue;
tbD.BorderThickness = new Thickness(2);
stackPanel2.Width = Double.NaN;
stackPanel2.Children.Add(tbD);
}
}
protected void Across()
{
IList<ModelSQL.puzzlecontent> lstAcross = daoPuzzleContent.GetAcross();
foreach (ModelSQL.puzzlecontent lista in lstAcross)
{
Label tbA = new Label();
tbA.Content = lista.Hint;
tbA.Width = Double.NaN;
tbA.BorderBrush = Brushes.CadetBlue;
tbA.BorderThickness = new Thickness(2);
stackPanel1.Width = Double.NaN;
stackPanel1.Children.Add(tbA);
words.Add(lista.Answer);
}
}
ToolTip
on eachControl
that displays the numbers?