Android测验 - 增加问题的难度级别

时间:2014-11-15 11:50:10

标签: java android

我有一个Android应用测验,目前从总共500个问题中选出每个游戏10个随机问题。我希望10个问题按照难度顺序出现,例如问题1是最容易的,逐渐越来越难以回答问题10,这是最困难的问题。想想“谁想要成为百万富翁”中的游戏玩法。

问题作为JSON存储在外部文件中。每个问题的难度级别("级别")从1到10.这是一个示例问题:

{"itemId":"747AF1F8A59F7DD132CB08E","itemType":"BT_quizQuestion","Category":"Music","Level":3,"questionText":"Bruce Springsteen is also known as ...","correctAnswerText":"The Boss","incorrectText1":"Prince of Darkness","incorrectText2":"God of Thunder","incorrectText3":"Old Pete"},

我随机选择10个问题的当前代码是:

//randomize questions from pool then grab "x" number for quiz
    if(questionPool.size() > 0 && (quizRandomizeQuestions.equals("1") || quizRandomizeQuestions.toUpperCase().equals("YES")  )){
        Collections.shuffle(questionPool);
        childItems = new ArrayList<BT_item>(); 
        for (int i = 0; i < questionPool.size(); i++){
            if(i < quizNumberOfQuestions){
                BT_item thisQuestion = questionPool.get(i);
                childItems.add(thisQuestion);
            }else{
                break;
            }
        }//end for each
    }else{
        //showAlert("No Questions?", "This quiz does not have any questions associated with it?");
    }

我已经确定我可以添加难度等级为1的问题(例如),如下所示:

String level = BT_strings.getJsonPropertyValue(thisQuestion.getJsonObject(), "Level", "");
                    if(level.equals("1")) childItems.add(thisQuestion);

但是如何在每场比赛中添加1个难度等级1,2,3,4,5,6,7,8,9和10个问题?

2 个答案:

答案 0 :(得分:0)

我正在尝试用一些随机代码帮助你,但是有正确的想法(至少对我而言)

private static final int MAX_QUESTIONS = 10;
List<Question> questionsList = new ArrayList<Question>();

for (int i = 0; i < MAX_QUESTIONS; i++) {

    Question quest = new Question();
    quest.getQuestionFromJsonFileWithLevel(i+1);
    questionsList.add(quest);

}

显然你有一个问题类,它代表你在json文件中的问题以及从中获取问题的方法

现在,在开始游戏之前,你将把所有问题都保存在列表中,而不需要在游戏中间查询它们

答案 1 :(得分:0)

不是循环问题池,而是循环查询所需的问题可能更好:

for(int count=0;count<10;count++){

对于每个循环,找到一个具有正确级别的问题:

    for(BT_item item:questionPool){ // loop through all the items in the question pool
        String level = BT_strings.getJsonPropertyValue(item.getJsonObject(), "Level", "");
        if(level.equals(String.valueOf(count+1))) {
            childItems.add(item); // add 1 to count because it starts at 0, but levels start at 1
            break; // found a question, so break the inner loop (but not the outer one)
        }
    }

然后结束第一个循环:

}