测验游戏下一个问题,如果回答跳过

时间:2013-11-24 10:25:39

标签: c# winforms

我的程序有一个问题。

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

并且我想制作一个按钮,如果我不知道答案(如ASK LATER),按下时会进入下一个问题

我有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)
{
}

2 个答案:

答案 0 :(得分:1)

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

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
    }
}

答案 1 :(得分:0)

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