我创建了 10 x 10 文本框,用户应该将单词输入到相关的文本框中以获取单词的位置。我将所有内容保存到这样的文本文件中:
然后在 WPF 方面,我阅读了文本文件并在面板中填充了文本框,但问题是填字游戏有向下和跨越提示,引导您找到答案,每个提示都有一个数字来指示哪个是哪个。但是,我想不出一种方法将数字的谜题编号与向下和跨数字的提示联系起来。这是它现在的样子:
注意横向和向下旁边的数字(我在油漆中编辑它们以可视化我想要的),我需要显示这些数字。
在我的数据库中,我将文件的位置存储在一个表中,并将提示和答案存储在另一个表中,如下所示:
这是提示(上下)和答案:
我正在使用实体框架 lambda 表达式来检索横向和向下。
感谢任何帮助,将数字分配给拼图中的 Across 和 Down。
这是我显示谜题的代码:
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()
显示 Across 和 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);
}
}