diff --git a/.idea/JavaSceneConfigState.xml b/.idea/JavaSceneConfigState.xml
index 99c9618..549fdfe 100644
--- a/.idea/JavaSceneConfigState.xml
+++ b/.idea/JavaSceneConfigState.xml
@@ -1,6 +1,6 @@
-
+
\ No newline at end of file
diff --git a/readme.md b/readme.md
index 0b6867e..c49a09e 100644
--- a/readme.md
+++ b/readme.md
@@ -6,9 +6,7 @@
> 灰色代表此单词中没有此字母
> 一共有单词长度+1次机会,机会用尽前猜中即为胜利
-## 仅支持windows,虽然有安卓和Linux版本但属于是只能亮其它功能随缘能用
-
-安卓平台目前无法正常使用存在一下问题:
+~~安卓平台目前无法正常使用存在一下问题:~~
1. ~~中文字体缺失~~(2024.08.26解决)
2. ~~文本输入组件不能正常输入~~(2024.09.12解决)
@@ -36,12 +34,15 @@
3. ~~解决ui布局问题~~
1. ~~ui布局存在问题,不应使用硬编码设置布局,应调整设置为居中~~
4. 增加GitHubAction自动打包
+ 1. widows未被官方支持
+ 2. linux一直报link失败的错误无法解决
5. 既然有数据库那就增加:
- 1. 统计系统
+ 1. 字体大小记忆
+ 2. 统计系统
1. 胜率
2. 历史记录
3. 游戏时长
6. 增加提示功能
- 1. 将黄色块单词的正确位置展示
+ 1. ~~将黄色块单词的正确位置展示~~ (2024.09.14实现)
7. 增加音效
1. 有生之年
\ No newline at end of file
diff --git a/src/main/java/caidanci/HelloController.java b/src/main/java/caidanci/HelloController.java
index 45f07c3..a5e5c19 100644
--- a/src/main/java/caidanci/HelloController.java
+++ b/src/main/java/caidanci/HelloController.java
@@ -9,10 +9,7 @@
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyEvent;
-import javafx.scene.layout.Background;
-import javafx.scene.layout.BackgroundFill;
-import javafx.scene.layout.CornerRadii;
-import javafx.scene.layout.GridPane;
+import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import javafx.scene.text.Font;
import org.kordamp.ikonli.bootstrapicons.BootstrapIcons;
@@ -27,6 +24,8 @@ public class HelloController {
private final SqlTools sqlTools = new SqlTools();
private final ThemeManager tm = ThemeManager.getInstance();
String[] theme = {new PrimerLight().getUserAgentStylesheet(), new PrimerDark().getUserAgentStylesheet()};
+ @FXML
+ private Spinner fontSize;
/**
* 主题 0 默认 1 暗黑
*/
@@ -35,6 +34,7 @@ public class HelloController {
* 单词长度
*/
private int wordLength = 5;
+ private String yellowWords = "";
private int inputTime = 0;
private boolean gameIsStart = false;
private String answerWord = "12345";
@@ -56,6 +56,8 @@ public class HelloController {
private Button startGame;
@FXML
private ComboBox fontChose;
+ @FXML
+ private Button showHint;
/**
* 切换主题
@@ -120,9 +122,11 @@ private void inputCheck(String inputText) {
inputTime--;
wordList.add(inputText);
refresh(inputText);
+ inputTimeUpdate();
if (inputText.equals(answerWord)) {
showAlert(Alert.AlertType.INFORMATION, "胜利!", "恭喜你,成功猜出单词!", answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
startGame();
+ return;
}
if (inputTime == 0) {
showAlert(Alert.AlertType.INFORMATION, "不,你失败了!", "你耗尽了机会!", "答案:" + answerWord + " :\n" + sqlTools.getWordInfo(answerWord));
@@ -130,12 +134,44 @@ private void inputCheck(String inputText) {
}
}
+ private void getYellowWord() {
+ StringBuilder sb = new StringBuilder();
+ for (var c : wordList) {
+ char[] chars = c.toCharArray();
+ for (var ch : chars) {
+ if (answerWord.contains(String.valueOf(ch))) {
+ sb.append(ch);
+ }
+ }
+ }
+ this.yellowWords = sb.toString();
+ }
+
+ private String retain(String str, String keepChar) {
+ StringBuilder sb = new StringBuilder();
+ for (var c : str.toCharArray()) {
+ if (keepChar.indexOf(c) != -1) {
+ sb.append(c);
+ } else {
+ sb.append(" ");
+ }
+ }
+ return sb.toString();
+ }
+
/**
* 刷新显示
*/
private void refresh(String inputText) {
+ refresh(inputText, outputGrid);
+ }
+
+ /**
+ * 刷新显示
+ */
+ private void refresh(String inputText, GridPane gridPane) {
int charSize = 40; // 每个字符的大小
- outputGrid.setAlignment(Pos.CENTER); // 居中对齐
+ gridPane.setAlignment(Pos.CENTER); // 居中对齐
// 将字符串分割成字符数组,并在每个格子中添加一个标签
char[] chars = inputText.toCharArray();
@@ -145,11 +181,11 @@ private void refresh(String inputText) {
label.setPrefSize(charSize, charSize);
label.setAlignment(Pos.CENTER); // 居中对齐
label.setBackground(new Background(new BackgroundFill(getColor(temp, i), CornerRadii.EMPTY, null)));
- label.setStyle("-fx-border-color: black; -fx-border-width: 1px;"); // 设置边框样式
- outputGrid.add(label, i, rowIndex); // 放置在第一行的不同列
+ label.setFont(inputButton.getFont());//与全局字体同步
+ label.setStyle("-fx-border-color: black; -fx-border-width: 1px;-fx-font-size: %d;".formatted(charSize)); // 设置边框样式
+ gridPane.add(label, i, rowIndex); // 放置在第一行的不同列
}
rowIndex++;
- inputTimeUpdate();
}
/**
@@ -166,17 +202,15 @@ private boolean checkWord(String word) {
*/
@FXML
void initialize() {
- Font a = Font.loadFont(Objects.requireNonNull(this.getClass().getResourceAsStream("fonts/fzjt.ttf")), 20);
+ Font a = Font.loadFont(Objects.requireNonNull(this.getClass().getResourceAsStream("fonts/fzjt.ttf")), 0);
Platform.runLater(() -> tm.setFontFamily(a.getFamily()));
tools.makeFontFamilyChooser(fontChose);
+ tools.makeFontSizeChooser(fontSize);
Platform.runLater(() -> Application.setUserAgentStylesheet(theme[themeFlag]));
changeTheme.setGraphic(new FontIcon(BootstrapIcons.MOON));
info.setGraphic(new FontIcon(BootstrapIcons.INFO_CIRCLE));
- startGame.setText("开始游戏");
- levelChose.setDisable(false);
- inputButton.setDisable(true);
- inputTextFiled.setDisable(true);
gameIsStart = false;
+ startGame();
SpinnerValueFactory valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(3, 10, wordLength);
levelChose.setValueFactory(valueFactory);
levelChose.valueProperty().addListener((observable, oldValue, newValue) -> {
@@ -184,6 +218,7 @@ void initialize() {
inputTimeUpdate();
});
inputTimeUpdate();
+ this.yellowWords = "";
}
/**
@@ -195,7 +230,7 @@ private void inputTimeUpdate() {
}
/**
- * 获取颜色
+ * 获取颜色并
*/
private Color getColor(String letter, int index) {
if (answerWord.contains(letter)) {
@@ -236,12 +271,13 @@ void infoButtonClicked() {
*/
@FXML
void startGame() {
- if (gameIsStart) {
+ if (!gameIsStart) {
startGame.setText("开始游戏");
levelChose.setDisable(false);
inputButton.setDisable(true);
inputTextFiled.setDisable(true);
- gameIsStart = false;
+ showHint.setDisable(true);
+ gameIsStart = true;
reset();
} else {
answerUpdate();
@@ -249,10 +285,12 @@ void startGame() {
levelChose.setDisable(true);
inputButton.setDisable(false);
inputTextFiled.setDisable(false);
- gameIsStart = true;
+ showHint.setDisable(false);
+ gameIsStart = false;
wordList = new ArrayList<>();
+ inputTimeUpdate();
}
- inputTimeUpdate();
+ this.yellowWords = "";
}
/**
@@ -280,7 +318,27 @@ private void showAlert(Alert.AlertType alertType, String title, String header, S
alert.setTitle(title);
alert.setHeaderText(header);
alert.setContentText(content);
- alert.initOwner(inputTextFiled.getScene().getWindow());
+
alert.showAndWait();
}
+
+ @FXML
+ void showHint() {
+ Alert alert = new Alert(Alert.AlertType.INFORMATION);
+ alert.initOwner(inputTextFiled.getScene().getWindow());
+ tm.addScene(alert.getDialogPane().getScene());
+ alert.setTitle("提示");
+ alert.setHeaderText(null);
+ // 创建自定义的内容
+ VBox content = new VBox();
+ // 添加自定义的节点,比如一个进度条
+ GridPane gridPane = new GridPane();
+ getYellowWord();
+ refresh(retain(answerWord, yellowWords), gridPane);
+ content.getChildren().add(gridPane);
+
+ // 设置对话框的内容
+ alert.getDialogPane().setContent(content);
+ alert.show();
+ }
}
diff --git a/src/main/java/caidanci/ThemeManager.java b/src/main/java/caidanci/ThemeManager.java
index 00786da..8414e7c 100644
--- a/src/main/java/caidanci/ThemeManager.java
+++ b/src/main/java/caidanci/ThemeManager.java
@@ -17,6 +17,7 @@ public class ThemeManager {
private final Map customCSSRules = new LinkedHashMap<>(); // .foo | -fx-property: value;
private final List scene = new ArrayList<>();
private String fontFamily = "FZKai-Z03S";
+ private Integer fontSize;
public static ThemeManager getInstance() {
return InstanceHolder.INSTANCE;
@@ -50,7 +51,6 @@ private void reloadCustomCSS() {
css.append("}\n");
});
for (Scene scene : getScene()) {
-
scene.getRoot().getStylesheets().removeIf(uri -> uri.startsWith("data:text/css"));
scene.getRoot().getStylesheets().add("data:text/css;base64," + Base64.getEncoder().encodeToString(css.toString().getBytes(UTF_8)));
scene.getRoot().pseudoClassStateChanged(USER_CUSTOM, true);
@@ -87,6 +87,14 @@ public void setFontFamily(String fontFamily) {
public void removeScene(Scene scene) {
this.scene.remove(scene);
+ }
+
+ public void setFontSize(Integer fontSize) {
+
+ setCustomDeclaration("-fx-font-size", fontSize.toString());
+
+ this.fontSize = fontSize;
+
reloadCustomCSS();
}
diff --git a/src/main/java/caidanci/tools.java b/src/main/java/caidanci/tools.java
index 4dabd47..3596cb4 100644
--- a/src/main/java/caidanci/tools.java
+++ b/src/main/java/caidanci/tools.java
@@ -5,6 +5,8 @@
import javafx.geometry.Rectangle2D;
import javafx.scene.control.ComboBox;
import javafx.scene.control.ListCell;
+import javafx.scene.control.Spinner;
+import javafx.scene.control.SpinnerValueFactory;
import javafx.scene.text.Font;
import javafx.stage.Screen;
@@ -82,4 +84,16 @@ protected void updateItem(String item, boolean empty) {
}
});
}
+
+ public static void makeFontSizeChooser(Spinner fontSize) {
+ SpinnerValueFactory valueFactory = new SpinnerValueFactory.IntegerSpinnerValueFactory(
+ 8, 72, 14);
+ fontSize.setValueFactory(valueFactory);
+ var tm = ThemeManager.getInstance();
+ // 添加监听器,当Spinner值改变时,更新Label的字体大小
+ fontSize.valueProperty().addListener((observable, oldValue, newValue) -> {
+ tm.setFontSize(newValue);
+ });
+
+ }
}
\ No newline at end of file
diff --git a/src/main/resources/caidanci/hello-view.fxml b/src/main/resources/caidanci/hello-view.fxml
index b8f091d..4240b48 100644
--- a/src/main/resources/caidanci/hello-view.fxml
+++ b/src/main/resources/caidanci/hello-view.fxml
@@ -1,39 +1,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
-
-
+
+
-
-
+
+
-
+
+
-
-
-
+
+
+
+
+
+
+