samedi 27 juin 2015

Trivia game design pattern

I need help with some design issues on creating a trivia quiz game. Before moving on i could use some advice if following approach is OK/Improvable/prone to failure/.. . This is what I have come up with so far:

public class Question {
    private String question;
    private List<Answer> answers;
    private int statisticsCorrectness;
}

public class Answer {
    private String answer;
    private boolean correct;
}

I than create questions in a holder class which I can use to get a set of questions (This is where im unsure, seems wrong to put it in a class, have never seen it before)

public class StaticStuff {

    public Module getModuleOne(){
        Module module;


        //Question1
        Answer a = new Answer("Ten", true);
        Answer a1 = new Answer("Five", false);
        Answer a2 = new Answer("Six", false);
        Answer a3 = new Answer("Eight", false);
        Answer a4 = new Answer("10", true);
        Answer[] listOfAn = new Answer[]{a, a1, a2, a3, a4};

        Question q1 = new Question("What is 5 plus 5", Arrays.asList(listOfAn));
        //End Question1

        //Question2
        //....
        //End Question2

        //Add all questions
        Question[] questionsForFirstModule = new Question[]{q1};

        //Create the module that will be returned
        module = new Module("Introduction", Arrays.asList(questionsForFirstLession));

        return module;
    }
}

The way I planned to use it would be to get each Module object saved in the SharedPreferences the first time the app runs (Using Json or parcelable). Than when I need the set of questions I just get the object from the SharedPreferences and send it back "updated" to SharedPreferences.

If a clear cut question need to be specified it would be: is there much drawback saving objects this fashion compared to using a database. Maybe I should go for a database approach (Something I just realized after writing all this) ?

I looked at the first three pages on google "Trivia game java tutorial" but didn't really get enough info from that.

Aucun commentaire:

Enregistrer un commentaire