cristi.gherghina
cristi.gherghina

Reputation: 321

quiz game nextquestion if answered skip over

i have one problem with my program.

I want to make an auto questionnaire.. like those from getting the car license.

and i want to make a button which when is pressed gets to the next question if i don't know the answer ( like ASK LATER)

i have 26 question. i made the function for the button if clicked question 1 gets the value of question 2. and so on. ( if is 26 gets the value of the question 1).

i want if i already answered to the question not to show again. like if i answered the second question and i am to the first question to skip over to the third question , not showing again the second.

i have a button submit. if clicked gets the next question . i have a label which text is "true" or "false" ( true if isn't answered, and false if answered).

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

and so on . this just gets to the next question. if is answered how can skip over?

note intrebare = question.

i want to make it in

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

Upvotes: 0

Views: 386

Answers (2)

har07
har07

Reputation: 89295

This is one way to do it, with basic OOP. Create Question class to represent your individual question

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

And in the Main class:

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

Upvotes: 1

tazyDevel
tazyDevel

Reputation: 536

Create a "Question" class and add all necessary properties and make sure you add a property "answered". Then create a generic list of questions (maybe random) into List<Question>. Finally query the list (e.g. by Linq) where question is not answered and question-number greater than current question number

Upvotes: 0

Related Questions