我正在做一个测验。我有一个结构设置,保持4个不同的字符串,第一个是问题编号,第二个是问题级别,第三个是问题,第四个是问题答案。我将此结构的数据存储在文本文件中。测试的想法是,如果用户得到正确的问题,用户将在第一级开始测试,他们将升级到2级问题。我甚至无法显示第一个问题,这是我到目前为止应该显示问题的代码部分。在那一刻,控制台窗口中的光标反复闪烁。
static void quiz(QuestionStruct[] _quiz)
{
bool asked = true;
int score = 0;
int AmountAsked = 0;
string level = "1";
string ans;
var pathToFile = @"..\..\..\Files\questions.txt";
using (StreamReader sr = new StreamReader(pathToFile, true))
{
while (AmountAsked < 20 || score >= 50)
{
Console.Clear();
int pos = 0;
if (level == "1" && questions[pos].Level == level) /* when i take && questions[pos].Level == level out of this if statement I get text on the console window but it starts with the question number, then i press enter and i get the question level and so on. */
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.Write(questions[pos].Question);
ans = Console.ReadLine();
if (ans == questions[pos].answer)
{
level = "2";
score = score + 1;
while (questions[pos].Level != "2")
{
pos++;
}
}
}
if (level == "2" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.WriteLine("{0}", questions[pos].Question);
ans = Console.ReadLine();
if (ans == questions[pos].answer)
{
level = "3";
score = score + 2;
while (questions[pos].Level != "3")
{
pos++;
}
}
else
{
level = "2";
}
}
if (level == "3" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.WriteLine("{0}", questions[pos].Question);
ans = Console.ReadLine();
if (ans == questions[pos].answer)
{
level = "4";
score = score + 3;
while (questions[pos].Level != "4")
{
pos++;
}
}
else
{
level = "2";
}
}
if (level == "4" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.WriteLine("{0}", questions[pos].Question);
ans = Console.ReadLine();
if (ans == questions[pos].answer)
{
level = "5";
score = score + 4;
while (questions[pos].Level != "5")
{
pos++;
}
}
else
{
level = "3";
}
}
while (level == "5" && questions[pos].Level == level)
{
AmountAsked++;
questions[pos].Question = sr.ReadLine();
Console.WriteLine("{0}", questions[pos].Question);
ans = Console.ReadLine();
if (ans == questions[pos].answer)
{
level = "5";
score = score + 5;
}
else
{
level = "4";
}
}
}
}
}