【问题标题】:quiz game nextquestion if answered skip over问答游戏下一个问题如果回答跳过
【发布时间】:2013-11-24 10:25:39
【问题描述】:

我的程序有一个问题。

我想制作一份汽车调查问卷……就像获得汽车执照一样。

如果我不知道答案(比如稍后提问),我想制作一个按钮,按下该按钮会进入下一个问题

我有 26 个问题。如果单击的问题 1 获得问题 2 的值,我为按钮创建了函数。依此类推。 (如果是 26 得到问题 1 的值)。

如果我已经回答了问题,我希望不再显示。就像我回答了第二个问题并且我要跳到第一个问题来跳到第三个问题,而不是再次显示第二个问题。

我有一个按钮提交。如果点击得到下一个问题。我有一个标签,其文本是“真”或“假”(如果没有回答,则为真,如果回答则为假)。

if (intrebare.Text == continutintrebare[0].Text && bifat[0].Text =="true")     //#2
{

    intrebare.Text = continutintrebare[1].Text;
    raspunstext[0, 0].Text = "marcheaza sfarsitul zonei unde este interzisa oprirea;";
    raspunstext[0, 1].Text = "marcheaza inceputul zonei unde este interzisa oprirea;";
    raspunstext[0, 2].Text = "marcheaza inceputul zonei unde este interzisa stationarea.";
    raspunstext[0, 0].BackColor = Color.White;
    raspunstext[0, 1].BackColor = Color.White;
    raspunstext[0, 2].BackColor = Color.White;
    imagine.BackgroundImage = new Bitmap(@"C:\Users\PC\Desktop\Chestionare\Chestionar Auto\Chestionar Auto\bin\Debug\imagini chestionar 1\2.jpg");
}
else
{
    if (intrebare.Text == continutintrebare[1].Text && bifat[1].Text == "true")  //#3
        {                
             intrebare.Text = continutintrebare[2].Text;
             raspunstext[0, 0].Text = "indicatorul 1;";
             raspunstext[0, 1].Text = "indicatorul 2;";
             raspunstext[0, 2].Text = "ambele indicatoare.";
             raspunstext[0, 0].BackColor = Color.White;
             raspunstext[0, 1].BackColor = Color.White;
             raspunstext[0, 2].BackColor = Color.White;
             imagine.BackgroundImage = new Bitmap(@"C:\Users\PC\Desktop\Chestionare\Chestionar Auto\Chestionar Auto\bin\Debug\imagini chestionar 1\3.jpg");
        }
        else
        {
             if (intrebare.Text == continutintrebare[2].Text && bifat[2].Text == "true") //#4
             {                                
                  intrebare.Text = continutintrebare[3].Text;
                  raspunstext[0, 0].Text = "autocamionul, autoturismul, motocicleta, troleibuzul;";
                  raspunstext[0, 1].Text = "troleibuzul, autocamionul, motocicleta, autoturismul;";
                  raspunstext[0, 2].Text = "autocamionul, autoturismul, troleibuzul, motocicleta.";
                  raspunstext[0, 0].BackColor = Color.White;
                  raspunstext[0, 1].BackColor = Color.White;
                  raspunstext[0, 2].BackColor = Color.White;
                  imagine.BackgroundImage = new Bitmap(@"C:\Users\PC\Desktop\Chestionare\Chestionar Auto\Chestionar Auto\bin\Debug\imagini chestionar 1\4.jpg");
            }
            else
            {
                 if (intrebare.Text == continutintrebare[3].Text && bifat[3].Text == "true") //#5
                 {                                   
                      intrebare.Text = continutintrebare[4].Text;
                      raspunstext[0, 0].Text = "va continuati drumul, deoarece aveti prioritate de trecere in sensul giratoriu;";
                      raspunstext[0, 1].Text = "opriti si acordati prioritate coloanei cu regim prioritar;";
                      raspunstext[0, 2].Text = "virati la dreapta si parasiti intersectia.";
                      raspunstext[0, 0].BackColor = Color.White;
                      raspunstext[0, 1].BackColor = Color.White;
                      raspunstext[0, 2].BackColor = Color.White;
                 }

等等。这只是下一个问题。如果被回答怎么能跳过?

注意 intrebare = 问题。

我想在

private void nextquestion_click(object sender, eventargs e)
{
}

【问题讨论】:

  • 我建议您重新表述您的问题。任何人(除了您)都不容易理解代码,尤其是当变量没有任何意义并且没有使用英文消息时。请使用英文消息和有意义的变量名...我也会删除任何与问题无关的代码(图像和背景不会影响程序的工作流程)。
  • 我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。

标签: c# winforms


【解决方案1】:

这是一种使用基本 OOP 的方法。创建 Question 类来代表您的个人问题

public class Question
{
    public int No;
    public string QuestionText;
    public bool isAnswered;
}

在主类中:

public class Main
{
    //your 26 questions stored in this variable
    public List<Question> questions;
    //current question shown
    public Question currentQuestion;

    public Main()
    {
        //initiate List
        questions = new List<Question>();
        //add question no.1
        var question1 = new Question();
        question1.No = 1;           
        question1.QuestionText = "What should I ask here?";
        question1.isAnswered = false;
        questions.Add(question1);
        //TODO: add question no.2 to 26

        //set current question to question no.1
        currentQuestion = question1;
    }

    private void nextquestion_click(object sender, eventargs e)
    {
        for(int i=1; i<=questions.Count; i++)
        {
            int nextQuestionNo = ((currentQuestion.No+i)%questions.Count);
            if(!questions[nextQuestionNo].isAnswered)
            {
                //next unanswered question found. set that as current question
                //then stop loop
                currentQuestion = questions[nextQuestionNo];
                break;
            }
        }

        //TODO: update the UI to show currentQuestion
    }
}

【讨论】:

  • 在该列表中如何添加问题?
  • 初始化问题列表,并将您的问题添加到 Main 构造函数中的列表中。我更新了代码以向您展示我的意思。您可能还想将我放在构造函数中的那些代码移动到其他函数,例如 CreateQuesions(),以便您可以简单地在构造函数中调用该函数。
  • 嗨@user2997809,如果您认为这个答案已经足够,请考虑将其标记为“已接受”。所以这个问题不再显示在未回答的问题列表中。谢谢
【解决方案2】:

创建一个“问题”类并添加所有必要的属性,并确保添加一个“已回答”属性。然后在List&lt;Question&gt; 中创建一个通用问题列表(可能是随机的)。最后查询未回答问题且问题编号大于当前问题编号的列表(例如通过 Linq)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-01
    • 1970-01-01
    • 2019-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-25
    相关资源
    最近更新 更多