|
|
|
|
@ -67,19 +67,62 @@ public class QuizView {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setQuizParameters(String level, int count) {
|
|
|
|
|
System.out.println("设置测验参数 - 级别: " + level + ", 题目数量: " + count);
|
|
|
|
|
|
|
|
|
|
this.currentLevel = level;
|
|
|
|
|
this.questionCount = count;
|
|
|
|
|
this.correctAnswers = 0;
|
|
|
|
|
|
|
|
|
|
// 生成题目
|
|
|
|
|
generateQuestions();
|
|
|
|
|
|
|
|
|
|
// 检查是否成功生成题目
|
|
|
|
|
if (questions == null || questions.isEmpty()) {
|
|
|
|
|
System.out.println("题目生成失败,显示空状态");
|
|
|
|
|
showEmptyState();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("成功生成 " + questions.size() + " 道题目,开始显示第一题");
|
|
|
|
|
showQuestion(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void generateQuestions() {
|
|
|
|
|
QuestionGenerator questionGenerator = QuestionService.createGenerator(currentLevel);
|
|
|
|
|
multipleChoiceGenerator = new MultipleChoiceGenerator(questionGenerator,currentLevel);
|
|
|
|
|
questions = multipleChoiceGenerator.generateMultipleChoiceQuestions(questionCount);
|
|
|
|
|
try {
|
|
|
|
|
System.out.println("开始生成题目,级别: " + currentLevel + ", 数量: " + questionCount);
|
|
|
|
|
|
|
|
|
|
QuestionGenerator questionGenerator = QuestionService.createGenerator(currentLevel);
|
|
|
|
|
if (questionGenerator == null) {
|
|
|
|
|
System.err.println("题目生成器创建失败,级别: " + currentLevel);
|
|
|
|
|
questions = java.util.Collections.emptyList();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
System.out.println("题目生成器创建成功: " + questionGenerator.getClass().getSimpleName());
|
|
|
|
|
|
|
|
|
|
multipleChoiceGenerator = new MultipleChoiceGenerator(questionGenerator, currentLevel);
|
|
|
|
|
questions = multipleChoiceGenerator.generateMultipleChoiceQuestions(questionCount);
|
|
|
|
|
|
|
|
|
|
System.out.println("题目生成完成,数量: " + (questions != null ? questions.size() : "null"));
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
System.err.println("生成题目时出现异常: " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
questions = java.util.Collections.emptyList();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showEmptyState() {
|
|
|
|
|
VBox root = (VBox) scene.getRoot();
|
|
|
|
|
root.getChildren().clear();
|
|
|
|
|
|
|
|
|
|
Label emptyLabel = new Label("无法生成题目,请返回重试");
|
|
|
|
|
emptyLabel.setFont(Font.font(16));
|
|
|
|
|
|
|
|
|
|
Button backButton = new Button("返回");
|
|
|
|
|
backButton.setOnAction(e -> sceneManager.showLevelSelectionView());
|
|
|
|
|
|
|
|
|
|
root.getChildren().addAll(emptyLabel, backButton);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void showQuestion(int index) {
|
|
|
|
|
|