Skip to content

Commit b912218

Browse files
committed
add update check & Version info
1 parent 2b18ba0 commit b912218

12 files changed

Lines changed: 205 additions & 12 deletions

.DS_Store

0 Bytes
Binary file not shown.

dependency-reduced-pom.xml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.eric</groupId>
5+
<artifactId>GobangGame</artifactId>
6+
<name>GoBangGame</name>
7+
<version>0</version>
8+
<description>Chinese game rewritten in java</description>
9+
<inceptionYear>2025</inceptionYear>
10+
<licenses>
11+
<license>
12+
<name>MIT</name>
13+
</license>
14+
</licenses>
15+
<organization>
16+
<name>Qiuerichanru</name>
17+
</organization>
18+
<build>
19+
<sourceDirectory>src/main/java</sourceDirectory>
20+
<resources>
21+
<resource>
22+
<directory>src/main/resources</directory>
23+
<excludes>
24+
<exclude>**/*.java</exclude>
25+
</excludes>
26+
</resource>
27+
</resources>
28+
<finalName>GobangGame</finalName>
29+
<plugins>
30+
<plugin>
31+
<groupId>de.perdian.maven.plugins</groupId>
32+
<artifactId>macosappbundler-maven-plugin</artifactId>
33+
<version>1.21.1</version>
34+
<executions>
35+
<execution>
36+
<phase>package</phase>
37+
<goals>
38+
<goal>bundle</goal>
39+
</goals>
40+
</execution>
41+
</executions>
42+
<configuration>
43+
<plist>
44+
<JVMMainClassName>com.eric.GobangGame.GobangGame</JVMMainClassName>
45+
</plist>
46+
<dmg>
47+
<generate>true</generate>
48+
</dmg>
49+
</configuration>
50+
</plugin>
51+
<plugin>
52+
<artifactId>maven-compiler-plugin</artifactId>
53+
<version>3.13.0</version>
54+
<configuration>
55+
<release>21</release>
56+
</configuration>
57+
</plugin>
58+
<plugin>
59+
<artifactId>maven-shade-plugin</artifactId>
60+
<version>3.6.1</version>
61+
<executions>
62+
<execution>
63+
<phase>package</phase>
64+
<goals>
65+
<goal>shade</goal>
66+
</goals>
67+
<configuration>
68+
<transformers>
69+
<transformer>
70+
<mainClass>com.eric.GobangGame.GobangGame</mainClass>
71+
</transformer>
72+
</transformers>
73+
</configuration>
74+
</execution>
75+
</executions>
76+
</plugin>
77+
<plugin>
78+
<groupId>com.akathist.maven.plugins.launch4j</groupId>
79+
<artifactId>launch4j-maven-plugin</artifactId>
80+
<version>2.6.0</version>
81+
<executions>
82+
<execution>
83+
<phase>package</phase>
84+
<goals>
85+
<goal>launch4j</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
<configuration>
90+
<outfile>target/GobangGame.exe</outfile>
91+
<jar>${project.build.directory}/${project.build.finalName}.jar</jar>
92+
<dontWrapJar>false</dontWrapJar>
93+
<headerType>gui</headerType>
94+
<jre>
95+
<minVersion>21</minVersion>
96+
</jre>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.skife.maven</groupId>
101+
<artifactId>really-executable-jar-maven-plugin</artifactId>
102+
<version>1.5.0</version>
103+
<executions>
104+
<execution>
105+
<phase>package</phase>
106+
<goals>
107+
<goal>really-executable-jar</goal>
108+
</goals>
109+
</execution>
110+
</executions>
111+
<configuration>
112+
<flags>-Xmx1G</flags>
113+
<programFile>${project.artifactId}</programFile>
114+
</configuration>
115+
</plugin>
116+
<plugin>
117+
<artifactId>maven-source-plugin</artifactId>
118+
<executions>
119+
<execution>
120+
<id>attach-sources</id>
121+
<goals>
122+
<goal>jar</goal>
123+
</goals>
124+
</execution>
125+
</executions>
126+
</plugin>
127+
</plugins>
128+
</build>
129+
<properties>
130+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
131+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
132+
</properties>
133+
</project>

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,11 @@
226226
</plugins>
227227
<finalName>GobangGame</finalName>
228228
</build>
229+
<dependencies>
230+
<dependency>
231+
<groupId>org.kohsuke</groupId>
232+
<artifactId>github-api</artifactId>
233+
<version>1.319</version>
234+
</dependency>
235+
</dependencies>
229236
</project>

src/main/java/com/eric/GobangGame/GobangGame.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import java.util.ArrayList;
77
import java.util.List;
88
import java.util.Locale;
9-
import java.util.ResourceBundle;
109

1110
/**
1211
* 五子棋游戏主类 - 协调器
1312
* 职责:管理游戏状态,协调 UI、Handler 和 AI 的交互
1413
*/
1514
public class GobangGame extends JFrame{
15+
16+
public static final double VERSION = 2.0;
1617

1718
// --- 棋盘常量 (仍保留在主类中,因为其他组件需要访问它们来确定尺寸) ---
1819
public static final int ROW = 15;

src/main/java/com/eric/GobangGame/GobangGameUI.java

Lines changed: 50 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,13 @@
77
import java.net.URI;
88
import java.net.URISyntaxException;
99
import java.util.Locale;
10+
import java.util.MissingResourceException;
1011
import java.util.ResourceBundle;
11-
import java.util.concurrent.ExecutionException;
12+
13+
import org.kohsuke.github.GitHub;
14+
import org.kohsuke.github.GitHubBuilder;
15+
import org.kohsuke.github.GHRelease;
16+
import org.kohsuke.github.GHRepository;
1217

1318
/**
1419
* 负责构建和管理所有用户界面元素(菜单、按钮、对话框)
@@ -24,13 +29,27 @@ public class GobangGameUI {
2429
private JButton undoBtn, restartBtn, closeBtn, loadBtn, saveBtn;
2530
private JMenuItem openItem, saveItem, closeItem, undoItem, restartItem, settingItem, aboutItem;
2631
private JMenu fileMenu, gameMenu, toolsMenu, aboutMenu;
27-
private JLabel aiState;
32+
private JLabel aiState, version;
2833

2934
public GobangGameUI(GobangGame game, Locale initialLocale) {
3035
this.game = game;
3136
setLanguage(initialLocale);
3237
}
3338

39+
public double GetLatestVer() {
40+
GHRelease release;
41+
try {
42+
GitHub github = new GitHubBuilder().withOAuthToken("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").build();
43+
GHRepository repo = github.getRepository("QIU2014/GobangGame");
44+
release = repo.getLatestRelease();
45+
double latestVer = Double.parseDouble(String.format("%s", release.getTagName()).replace("GobangGame_v", ""));
46+
return latestVer;
47+
} catch (IOException e) {
48+
e.printStackTrace();
49+
return 0.0;
50+
}
51+
}
52+
3453
public ResourceBundle getMessages() {
3554
return messages;
3655
}
@@ -90,19 +109,32 @@ public JPanel createButtonPanel() {
90109
// 回到原来的FlowLayout,但减少垂直间距
91110
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 0, 30));
92111
buttonPanel.setPreferredSize(new Dimension(game.getBUTTON_WIDTH(), game.getHeight()));
93-
try {
94-
this.saveBtn = new JButton(messages.getString("button.save"));
95-
this.loadBtn = new JButton(messages.getString("button.load"));
96-
} catch (Exception e) {
97-
System.out.println(e.getMessage());
98-
System.out.println("Falling back to hard-coded text");
99-
this.saveBtn = new JButton("Save");
100-
this.loadBtn = new JButton("Open");
101-
}
112+
this.saveBtn = new JButton(messages.getString("button.save"));
113+
this.loadBtn = new JButton(messages.getString("button.load"));
102114
this.undoBtn = new JButton(messages.getString("button.undo"));
103115
this.restartBtn = new JButton(messages.getString("button.restart"));
104116
this.closeBtn = new JButton(messages.getString("button.exit"));
117+
105118
this.aiState = new JLabel("AI: IDLE", SwingConstants.CENTER);
119+
try {
120+
if (GetLatestVer() > GobangGame.VERSION) {
121+
this.version = new JLabel(messages.getString("version.update") + "v" + GetLatestVer(), SwingConstants.CENTER);
122+
version.setForeground(Color.RED);
123+
} else {
124+
this.version = new JLabel("Version" + GobangGame.VERSION, SwingConstants.CENTER);
125+
version.setForeground(Color.GREEN);
126+
}
127+
} catch (MissingResourceException e) {
128+
e.printStackTrace();
129+
System.out.println("Missing resource! Falling back to hard-coded");
130+
if (GetLatestVer() > GobangGame.VERSION) {
131+
this.version = new JLabel("Update detected: " + "v" + GetLatestVer(), SwingConstants.CENTER);
132+
version.setForeground(Color.RED);
133+
} else {
134+
this.version = new JLabel("GobangGame v" + GobangGame.VERSION, SwingConstants.CENTER);
135+
version.setForeground(Color.GREEN);
136+
}
137+
}
106138

107139
Dimension btnSize = new Dimension(game.getBUTTON_WIDTH(), game.getBUTTON_HEIGHT());
108140

@@ -120,6 +152,7 @@ public JPanel createButtonPanel() {
120152
restartBtn.setFont(font);
121153
closeBtn.setFont(font);
122154
aiState.setFont(font);
155+
version.setFont(font);
123156

124157
// 设置AI标签样式
125158
aiState.setForeground(Color.BLUE);
@@ -146,6 +179,12 @@ public JPanel createButtonPanel() {
146179
// 添加AI标签
147180
buttonPanel.add(aiState);
148181

182+
JSeparator separator_1 = new JSeparator(SwingConstants.HORIZONTAL);
183+
separator_1.setPreferredSize(new Dimension(game.getBUTTON_WIDTH() - 20, 2));
184+
buttonPanel.add(separator_1);
185+
186+
buttonPanel.add(version);
187+
149188
return buttonPanel;
150189
}
151190

src/main/resources/messages_de_DE.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ game.white=Wei�
55
game.win= gewinnt!
66
game.draw=Unentschieden!
77

8+
version.update=Update Detected
9+
810
# Buttons
911
button.undo=R�ckg�ngig
1012
button.restart=Spiel neu starten

src/main/resources/messages_en_US.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ game.white=White
55
game.win= wins!
66
game.draw=Draw!
77

8+
version.update=Update Detected!
9+
810
# Buttons
911
button.undo=Undo
1012
button.restart=Restart Game

src/main/resources/messages_ko_KP.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ game.white=\uD790\uC0C9 \uC7A1\uC73C
55
game.win=\uC2B9\uB9AC\uC785\uB2C8\uB2E4\uFF01
66
game.draw=\uBE44\uACA9\uC785\uB2C8\uB2E4\uFF01
77

8+
version.update=Update Detected
9+
810
# Buttons
911
button.undo=\uB418\uB3CC\uB9AC\uAE30
1012
button.restart=\uAC8C\uC784 \uC7AC\uC2DC\uC791

src/main/resources/messages_ko_KR.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ game.white=\uD790\uC0C9 \uC7A1\uC73C
55
game.win=\uC2B9\uB9AC\uC785\uB2C8\uB2E4\uFF01
66
game.draw=\uBE44\uACA9\uC785\uB2C8\uB2E4\uFF01
77

8+
version.update=Update Detected
9+
810
# Buttons
911
button.undo=\uB418\uB3CC\uB9AC\uAE30
1012
button.restart=\uAC8C\uC784 \uC7AC\uC2DC\uC791

src/main/resources/messages_ni_PD.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ game.white=Pay
55
game.win= holum!
66
game.draw=Holumkawng!
77

8+
version.update=Update Detected
9+
810
# Buttons
911
button.undo=Slele
1012
button.restart=Sngä'i Hìkrr Pongu

0 commit comments

Comments
 (0)