Set difficulty for a question and when selecting difficulty seek only those questions

Asked

Viewed 35 times

0

Good afternoon!

I am finishing a C# Quiz made in Unity. The question I have is, I have several questions that I would like to see an Asset. But I need to set the difficulties for each of the issues. And by clicking on the Easy difficulty menu, I want it to only load those questions that are with the selected difficulty. But I am having difficulty. I will put here the code of my class that creates the question.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif


[CreateAssetMenuAttribute]

public class QuizQuestion : ScriptableObject {
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }

    //Campos que receberão dados do arquivo .xml ou .json
    [SerializeField]
    private string pergunta;
    [SerializeField]
    private string[] respostas;
    [SerializeField]
    private int respostaCorreta;

    //Métodos para buscar as perguntas, opções, resposta correta e dificuldade
    public string Pergunta { get { return pergunta; } }
    public string[] Respostas { get { return respostas; } }
    public int RespostaCorreta { get { return respostaCorreta; } }

    //public int Dificuldade {  get { return dificuldade; } }

    public bool Asked { get; internal set; }

    //Validar a resposta
    private void OnValidate()
    {
        if (respostaCorreta > respostas.Length)
        {
            respostaCorreta = 0;
        }

       RenomearObjetoDeAcordoComPerguntaResposta();
    }

    private void RenomearObjetoDeAcordoComPerguntaResposta()
    {
        string desiredName = string.Format("{0} [{1}]",
            pergunta.Replace("?", ""),
            respostas[respostaCorreta]);

        string assetPath = AssetDatabase.GetAssetPath(this.GetInstanceID());
        string shouldEndWith = "/" + desiredName + ".asset";
        if (assetPath.EndsWith(shouldEndWith) == false)
        {
            Debug.Log("Want to rename to " + desiredName);
            AssetDatabase.RenameAsset(assetPath, desiredName);
            AssetDatabase.SaveAssets();
        }
    }
}

Thank you in advance!

  • I don’t see any attribute related to the level of difficulty of Pergunta

1 answer

0

All right?

You can create reference to the questions, with numbers, for example. Let’s assume that in the list there are 30 questions and they are divided in the 3 difficulties: easy(1), medium(2) and difficult(3).

Then the player chooses the difficulty, so (pseudo-code):

 \\aqui é a variavel que recebe a escolha da dificuldade
 int escolha_do_jogador = escolha;

  \\aqui analisa a escolha, no caso, a escolha é 1, logo, é a dificuldade facil.
 if(escolha do jogador == 1)
    {
       for(int i = 0; i <= 10;i++)
       {
          \\as questões faceis, neste caso, são as 10 primeiras da lista
          exibirQuestao = questao[i]; 
       }
    }
     \\dificuldade media
 if(escolha do jogador == 2)
    {
       for(int i = 0; i <= 10;i++)
       {
           \\aqui, a dificuldade media está de 10 a 20
          exibirQuestao = questao[i+10]; 
       }
    }
 if(escolha do jogador == 3)
    {
       for(int i = 0; i <= 10;i++)
       {
          \\aqui, a dificuldade esta no dificil, de 20 a 30
          exibirQuestao = questao[i+20]; 
       }
    }

It’s an example code, adapt your code to that thought.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.