测试版 #4

Merged
ppy4sjqvf merged 10 commits from master into develop 4 months ago

@ -30,45 +30,56 @@ public class SceneManager {
}
public void showLoginView() {
System.out.println("切换到登录界面");
primaryStage.setScene(loginView.getScene());
primaryStage.show();
}
public void showRegisterView() {
System.out.println("切换到注册界面");
primaryStage.setScene(registerView.getScene());
primaryStage.show();
}
public void showMainMenuView() {
System.out.println("切换到主菜单界面");
// 在显示主菜单前更新用户名
if (mainMenuView != null) {
mainMenuView.updateUsername(currentUserName);
}
if (mainMenuView != null) {
primaryStage.setScene(mainMenuView.getScene());
}
primaryStage.setScene(mainMenuView.getScene());
primaryStage.show(); // 添加这行
}
public void showLevelSelectionView() {
System.out.println("切换到级别选择界面");
// 在显示级别选择界面前更新用户名
if (levelSelectionView != null) {
levelSelectionView.updateUsername(currentUserName);
}
if (levelSelectionView != null) {
primaryStage.setScene(levelSelectionView.getScene());
}
primaryStage.setScene(levelSelectionView.getScene());
primaryStage.show(); // 添加这行
}
public void showQuestionCountView() {
System.out.println("切换到题目数量选择界面");
primaryStage.setScene(questionCountView.getScene());
primaryStage.show(); // 添加这行
}
public void showQuizView() {
public void showQuizView(String level, int count) {
System.out.println("切换到答题界面 - 级别: " + level + ", 题目数量: " + count);
// 设置测验参数
quizView.setQuizParameters(level, count);
primaryStage.setScene(quizView.getScene());
primaryStage.show();
}
public void showResultView(double score) {
System.out.println("切换到结果界面,分数: " + score);
resultView.setScore(score);
primaryStage.setScene(resultView.getScene());
primaryStage.show(); // 添加这行
}
// Getter methods for views
@ -79,6 +90,13 @@ public class SceneManager {
public QuestionCountView getQuestionCountView() { return questionCountView; }
public QuizView getQuizView() { return quizView; }
public ResultView getResultView() { return resultView; }
public void setCurrentUserName(String currentUserName){ this.currentUserName = currentUserName;}
public String getCurrentUserName(){return this.currentUserName;}
public void setCurrentUserName(String currentUserName) {
this.currentUserName = currentUserName;
System.out.println("设置当前用户名: " + currentUserName);
}
public String getCurrentUserName() {
return this.currentUserName;
}
}

@ -65,7 +65,7 @@ public class LevelSelectionView {
avatarCircle.setStrokeWidth(2);
// 添加阴影效果
avatarCircle.setStyle("-fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
// 添加首字母文本
avatarText = new Text(getFirstLetter());
@ -151,18 +151,18 @@ public class LevelSelectionView {
Button button = new Button(text);
button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
color
));
button.setPrefSize(220, 60);
button.setOnMouseEntered(e -> button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);",
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.3), 10, 0.4, 3, 3);",
hoverColor
)));
button.setOnMouseExited(e -> button.setStyle(String.format(
"-fx-background-color: %s; -fx-text-fill: white; -fx-font-size: 16px; -fx-font-weight: bold; " +
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
"-fx-background-radius: 12; -fx-padding: 12 30; -fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 8, 0.3, 2, 2);",
color
)));
return button;

@ -69,7 +69,7 @@ public class MainMenuView {
avatarCircle.setStrokeWidth(2);
// 添加阴影效果
avatarCircle.setStyle("-fx-effect: drop shadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
avatarCircle.setStyle("-fx-effect: dropshadow(gaussian, rgba(0,0,0,0.2), 5, 0.3, 2, 2);");
// 添加首字母文本
avatarText = new Text(getFirstLetter());

@ -58,9 +58,8 @@ public class QuestionCountView {
return;
}
// 设置题目数量和级别,然后开始答题
sceneManager.getQuizView().setQuizParameters(level, count);
sceneManager.showQuizView();
// 直接调用 showQuizView 并传递参数
sceneManager.showQuizView(level, count);
} catch (NumberFormatException ex) {
showError(statusLabel, "请输入有效的数字!");

@ -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) {

@ -1,132 +0,0 @@
package com.ybw.mathapp;
// UserService.java
import com.ybw.mathapp.entity.User;
import com.ybw.mathapp.service.EmailService;
import com.ybw.mathapp.util.LoginFileUtils;
import java.util.Scanner;
import java.util.regex.Pattern;
public class LoginAndRegister {
private static Scanner scanner = new Scanner(System.in);
// UserService.java 中的注册方法更新
public static boolean register() {
System.out.println("\n=== 用户注册 ===");
// 输入邮箱
System.out.print("请输入邮箱地址: ");
String email = scanner.nextLine().trim();
if (!isValidEmail(email)) {
return false;
}
if (LoginFileUtils.isEmailRegistered(email)) {
System.out.println("该邮箱已注册,请直接登录!");
return false;
}
// 发送、验证验证码
if (!sendAndVerifyCode(email)) {
return false;
}
// 设置密码(其余代码保持不变)
System.out.print("请输入密码: ");
String password1 = scanner.nextLine();
System.out.print("请再次输入密码: ");
String password2 = scanner.nextLine();
if(!isVaildPassword(password1, password2)) {
return false;
}
User user = new User(email, password1);
LoginFileUtils.saveUser(user);
System.out.println("注册成功!您可以使用邮箱和密码登录了。");
return true;
}
// 登录流程
public static boolean login() {
System.out.println("\n=== 用户登录 ===");
System.out.print("请输入邮箱: ");
String email = scanner.nextLine().trim();
System.out.print("请输入密码: ");
String password = scanner.nextLine();
if (LoginFileUtils.validateUser(email, password)) {
System.out.println("登录成功!欢迎回来," + email);
return true;
} else {
System.out.println("邮箱或密码错误!");
return false;
}
}
//
/**
*
* @param email
* @return truefalse
*/
private static boolean isValidEmail(String email) {
if (email.isEmpty()) {
System.out.println("邮箱地址不能为空!");
return false;
}
if (!(email.contains("@") && email.contains("."))) {
System.out.println("邮箱格式不正确!");
return false;
}
return true;
}
/**
*
* @param password1
* @param password2
* @return truefalse
*/
public static boolean isVaildPassword(String password1, String password2) {
if (password1 == null || password1.length() < 6 || password1.length() > 10) {
return false;
}
// 使用正则表达式验证长度6-10只包含字母数字且包含大小写字母和数字
String regex = "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)[a-zA-Z\\d]{6,10}$";
if (!Pattern.matches(regex, password1)) {
return false;
}
System.out.print("请再次输入密码: ");
if (!password1.equals(password2)) {
System.out.println("两次输入的密码不一致!");
return false;
}
return true;
}
public static boolean sendAndVerifyCode(String email) {
// 发送真实邮件验证码
String verificationCode = EmailService.generateVerificationCode();
System.out.println("正在发送验证码邮件,请稍候...");
if (!EmailService.sendVerificationCode(email, verificationCode)) {
System.out.println("发送验证码失败,请检查邮箱配置或稍后重试!");
return false;
}
// 验证验证码
System.out.print("请输入收到的验证码: ");
String inputCode = scanner.nextLine().trim();
if (!EmailService.verifyCode(email, inputCode)) {
System.out.println("验证码错误或已过期!");
return false;
}
return true;
}
}

@ -4,11 +4,13 @@ import com.ybw.mathapp.entity.QuestionWithOptions;
import com.ybw.mathapp.service.JuniorHighGenerator;
import com.ybw.mathapp.service.MultipleChoiceGenerator;
import com.ybw.mathapp.service.PrimarySchoolGenerator;
import com.ybw.mathapp.service.SeniorHighGenerator;
import java.util.List;
public class Main {
public static void main(String[] args) {
// 生成小学选择题
System.out.println("--- Primary School MCQs ---");
PrimarySchoolGenerator primaryGen = new PrimarySchoolGenerator();
MultipleChoiceGenerator primaryMC = new MultipleChoiceGenerator(primaryGen, "小学"); // 传入级别
@ -21,16 +23,15 @@ public class Main {
MultipleChoiceGenerator juniorMC = new MultipleChoiceGenerator(juniorGen, "初中"); // 传入级别
List<QuestionWithOptions> juniorMCQs = juniorMC.generateMultipleChoiceQuestions(10);
juniorMCQs.forEach(q -> System.out.println(q + "\n"));
System.out.println();
/*
// 生成高中选择题
System.out.println("--- Senior High MCQs ---");
SeniorHighGenerator seniorGen = new SeniorHighGenerator();
MultipleChoiceGenerator seniorMC = new MultipleChoiceGenerator(seniorGen, "高中"); // 传入级别
List<QuestionWithOptions> seniorMCQs = seniorMC.generateMultipleChoiceQuestions(2, 4);
List<QuestionWithOptions> seniorMCQs = seniorMC.generateMultipleChoiceQuestions(10);
seniorMCQs.forEach(q -> System.out.println(q + "\n"));
*/
}
}

@ -46,7 +46,6 @@ public class MultipleChoiceGenerator {
// 例如,如果基础生成器的可能组合用尽了
break; // 或者抛出异常
}
QuestionWithOptions mcq = generateSingleMCQ(baseQuestion);
if (mcq != null) {
mcQuestions.add(mcq);
@ -153,10 +152,13 @@ public class MultipleChoiceGenerator {
tokens.add(token);
i += token.length();
} else {
i++;
} /* else {
// 如果找不到匹配的 token可能是单个字符或未知格式
tokens.add(String.valueOf(expression.charAt(i)));
i++;
}
*/
}
return tokens;
}

@ -72,9 +72,13 @@ public class PrimarySchoolGenerator implements QuestionGenerator {
}
}
}
if (AdvancedCaculate.calculate(parts) >= 0) {
return String.join(" ", parts) + " =";
} else {
try {
if (AdvancedCaculate.calculate(parts) >= 0) {
return String.join(" ", parts) + " =";
} else {
parts.clear();
}
} catch (ArithmeticException | IllegalArgumentException e) {
parts.clear();
}
}

@ -1,2 +1,2 @@
wsf,3310207578@qq.com,Wsf1234
ybw,1798231811@qq.com,Ybw1234

Loading…
Cancel
Save