added TODOs for many things that need to be done in the backend

master
BodgeMaster 2022-02-20 21:15:50 +01:00
parent 06160852fc
commit 56eaf9a9b3
1 changed files with 66 additions and 10 deletions

View File

@ -1,48 +1,98 @@
package linux.general.hackyquizbot; package linux.general.hackyquizbot;
import java.util.ArrayList;
public class QuizBackend { public class QuizBackend {
private static Question[] allQuestions;
private static String[] categories;
static {
//TODO: populate allQuestions
//TODO: populate categories
}
public static String[] getCategories() { public static String[] getCategories() {
return null; return categories;
} }
public static Question getRandomQuestionForCategory(String category) { public static Question getRandomQuestionForCategory(String category) {
//TODO: loop
//TODO: pick random question
//TODO: check if question is in category, return if it is
return null;
}
public static Question getNewRandomQuestionForCategory(String discordUserID, String category) {
//TODO: get list of previously displayed questions for that user
//TODO: retrieve list of answers that user has given to get the question IDs from there
//TODO: find a random question that isnt on said list
//TODO: add the question to said list and return it
return null; return null;
} }
public static int getScoreForUser(String discordUserID) { public static int getScoreForUser(String discordUserID) {
return 0; int score = 0;
//TODO: iterate over all questions
//TODO: get achieved score for the user for the question
//TODO: add to score
return score;
} }
public static class Question { public static class Question {
private String text;
private char[] validAnswers;
private char[] correctAnswers;
private int scoreValue;
private int ID;
private ArrayList<String> categories = new ArrayList<String>();
/** /**
* * @param ID unique ID for the question
* @param question The string for the question text * @param question The string for the question text
* @param answers The multiple choice answers * @param answers The multiple choice answers
* @param mask A mask to be laid over answers to decide which answers are correct and which arent * @param mask A mask to be laid over answers to decide which answers are correct and which arent
* @param scoreValue See getQuestionScoreValue() * @param scoreValue See getQuestionScoreValue()
*/ */
public Question(String question, String[] answers, boolean[] mask, int scoreValue) { public Question(int ID, String question, String[] answers, boolean[] mask, int scoreValue) {
//TODO: build text, valid answers and correct answers
this.ID = ID;
this.scoreValue = scoreValue;
}
//TODO: need a way to get back from the answer letter to the text answer and vice versa
public boolean isInCategory(String category) {
for (int i=0; i<this.categories.size(); i++) {
if (this.categories.get(i).equals(category)) return true;
}
return false;
}
public void addCategory(String category) {
this.categories.add(category);
} }
/** /**
* @return the full question text including multiple choice options with letters that correspond to getValidResponses() * @return the full question text including multiple choice options with letters that correspond to getValidResponses()
*/ */
public String getQuestionTextWithOptions() { public String getQuestionTextWithOptions() {
return null; return text;
} }
/** /**
* @return a character array containing all the valid answers * @return a character array containing all the valid answers
*/ */
public char[] getValidResponses() { public char[] getValidResponses() {
return null; return this.validAnswers;
} }
/**
* @return a character array containing all the correct answers
*/
public char[] getCorrectResponses() { public char[] getCorrectResponses() {
return null; return this.correctAnswers;
} }
/** /**
@ -53,7 +103,7 @@ public class QuizBackend {
* @param answer * @param answer
*/ */
public void addAnswer(String discordUserID, char answer) { public void addAnswer(String discordUserID, char answer) {
//TODO: store question ID, user ID, and the chosen answer
} }
/** /**
@ -64,6 +114,12 @@ public class QuizBackend {
* @return * @return
*/ */
public int getQuestionScoreValue() { public int getQuestionScoreValue() {
return this.scoreValue;
}
public int getAchievedScore(String discordUserID) {
//TODO: retrieve given answers by user ID and question ID
//TODO: calculate score
return 0; return 0;
} }
} }