37 lines
886 B
TypeScript
37 lines
886 B
TypeScript
// 奇遇题库
|
|
import {readFileAndParse} from '../util'
|
|
import { FILENAME } from '../../consts'
|
|
|
|
export interface DicQuestion {
|
|
// 题目id
|
|
readonly id: number;
|
|
// 题干
|
|
readonly question: string;
|
|
// 答案
|
|
readonly answer: Array<string>;
|
|
// 正确答案
|
|
readonly correct: number;
|
|
|
|
}
|
|
|
|
export const dicQuestion = new Map<number, DicQuestion>();
|
|
export function loadQuestion() {
|
|
dicQuestion.clear();
|
|
|
|
let arr = readFileAndParse(FILENAME.DIC_QUESTION);
|
|
|
|
arr.forEach(o => {
|
|
o.answer = parseAnswer(o.a1, o.a2, o.a3, o.a4)
|
|
dicQuestion.set(o.id, o);
|
|
});
|
|
arr = undefined;
|
|
}
|
|
|
|
function parseAnswer(a1: string, a2: string, a3: string, a4: string) {
|
|
let answer = new Array<string>();
|
|
if(a1) answer.push(a1);
|
|
if(a2) answer.push(a2);
|
|
if(a3) answer.push(a3);
|
|
if(a4) answer.push(a4);
|
|
return answer;
|
|
} |