Set difficulty for a question and when selecting the difficulty to search only those questions

0

Good afternoon!

I'm finalizing a C # Quiz done in Unity. The question I have is, I have several issues that I generate via 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 issues that are with the selected difficulty. But I'm having trouble. I'll 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!

    
asked by anonymous 28.10.2018 / 01:02

1 answer

0

Alright?

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

Then the player chooses the difficulty, soon (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 a sample code, adapt your code to that thought.

    
31.10.2018 / 14:10