Loading src/controller/AppController.java +20 −8 Changes for src/controller/AppController.java: 20 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -55,6 +55,13 @@ public class AppController { return savedGame; } /** * 进入房间选择页面 * * @throws ExecutionException * @throws InterruptedException */ public static void goRooms() throws ExecutionException, InterruptedException { while(true) { CompletableFuture<FrameReturnType<RoomFrame>> roomFuture = new CompletableFuture<>(); Loading @@ -71,6 +78,12 @@ public class AppController { } } /** * 进入本地游戏 * * @throws ExecutionException * @throws InterruptedException */ public static void goOfflineGame(boolean useSave, GameType type) throws ExecutionException, InterruptedException { CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture = new CompletableFuture<>(); SwingUtilities.invokeLater(() -> { Loading @@ -90,6 +103,12 @@ public class AppController { ChessGameFrame.instance.dispose(); } /** * 进入联机游戏 * * @throws ExecutionException * @throws InterruptedException */ public static void goOnlineGame(OnlineStatus onlineMode, Room room) throws ExecutionException, InterruptedException { CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture = new CompletableFuture<>(); Game.instance = new Game(GameType.ONLINE); Loading Loading @@ -152,9 +171,7 @@ public class AppController { jsonObject.put("Game", Game.instance); jsonObject.put("History", History.instance); File save = new File(path); if (!save.exists()) { save.createNewFile(); } save.createNewFile(); // 不覆盖已有存档 Files.writeString(Path.of(path), JSON.toJSONString(jsonObject)); read(path); return true; Loading @@ -181,11 +198,6 @@ public class AppController { CompletableFuture<FrameReturnType<AppFrame>> appFuture = new CompletableFuture<>(); SwingUtilities.invokeLater(() -> { AppFrame.instance = new AppFrame(appFuture); AppFrame.instance.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { super.windowClosing(e); } }); }); FrameReturnType<AppFrame> result = appFuture.get(); AppFrame.instance.setVisible(false); Loading src/controller/ChessClickController.java +2 −2 Changes for src/controller/ChessClickController.java: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -94,11 +94,11 @@ public enum ChessClickController { ChessGameFrame.instance.refreshScore(1); if(Game.instance.getScoreboard()[0] >= 60){ JOptionPane.showMessageDialog(null, "红方胜利", "提示", JOptionPane.WARNING_MESSAGE); ChessGameFrame.instance.getFuture().complete(new exitGame()); ChessGameFrame.instance.exit(); } if(Game.instance.getScoreboard()[1] >= 60){ JOptionPane.showMessageDialog(null, "黑方胜利", "提示", JOptionPane.WARNING_MESSAGE); ChessGameFrame.instance.getFuture().complete(new exitGame()); ChessGameFrame.instance.exit(); } } Loading src/view/Frame/AppFrame.java +14 −8 Changes for src/view/Frame/AppFrame.java: 14 added lines, 8 removed lines. Original line number Diff line number Diff line package view.Frame; import view.Frame.AppFrameReturnType.exitApp; import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.concurrent.CompletableFuture; public class AppFrame extends JFrame { public static AppFrame instance; private CompletableFuture<FrameReturnType<AppFrame>> future; public CompletableFuture<FrameReturnType<AppFrame>> getFuture() { return future; } private final CompletableFuture<FrameReturnType<AppFrame>> future; public AppFrame(CompletableFuture<FrameReturnType<AppFrame>> future) { this.future = future; public AppFrame(CompletableFuture<FrameReturnType<AppFrame>> appFuture) { this.future = appFuture; this.setLocation(400,0); this.setContentPane(new StartForm().rootPanel); this.setContentPane(new StartForm(this.future).rootPanel); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { future.complete(new exitApp()); super.windowClosing(e); } }); this.pack(); this.setVisible(true); } Loading src/view/Frame/ChessGameFrame.java +4 −4 Changes for src/view/Frame/ChessGameFrame.java: 4 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -37,10 +37,6 @@ public class ChessGameFrame extends JFrame { private JTextArea actionHistoryArea ; public JTextArea[] score = new JTextArea[2]; public CompletableFuture<FrameReturnType<ChessGameFrame>> getFuture() { return future; } public ChessGameFrame(CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture) { this.future = gameFuture; setTitle("2022 CS109 Project Demo"); //设置标题 Loading Loading @@ -355,6 +351,10 @@ public class ChessGameFrame extends JFrame { playerListArea.append(s + "\r\n"); } public void exit(){ future.complete(new exitGame()); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // ChessGameFrame mainFrame = new ChessGameFrame(); Loading src/view/Frame/RoomFrame.java +1 −5 Changes for src/view/Frame/RoomFrame.java: 1 added line, 5 removed lines. Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ public class RoomFrame extends JFrame { public static RoomFrame instance; public CompletableFuture<FrameReturnType<RoomFrame>> getFuture() { return future; } private CompletableFuture<FrameReturnType<RoomFrame>> future; private JPanel roomPane; Loading Loading @@ -77,7 +73,7 @@ public class RoomFrame extends JFrame { button.setFont(new Font("Rockwell", Font.BOLD, 20)); button.addActionListener(e -> { future.complete(new goOnline(OnlineStatus.SERVER_WAITING, null)); this.future.complete(new goOnline(OnlineStatus.SERVER_WAITING, null)); }); setPane.add(button); } Loading Loading
src/controller/AppController.java +20 −8 Changes for src/controller/AppController.java: 20 added lines, 8 removed lines. Original line number Diff line number Diff line Loading @@ -55,6 +55,13 @@ public class AppController { return savedGame; } /** * 进入房间选择页面 * * @throws ExecutionException * @throws InterruptedException */ public static void goRooms() throws ExecutionException, InterruptedException { while(true) { CompletableFuture<FrameReturnType<RoomFrame>> roomFuture = new CompletableFuture<>(); Loading @@ -71,6 +78,12 @@ public class AppController { } } /** * 进入本地游戏 * * @throws ExecutionException * @throws InterruptedException */ public static void goOfflineGame(boolean useSave, GameType type) throws ExecutionException, InterruptedException { CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture = new CompletableFuture<>(); SwingUtilities.invokeLater(() -> { Loading @@ -90,6 +103,12 @@ public class AppController { ChessGameFrame.instance.dispose(); } /** * 进入联机游戏 * * @throws ExecutionException * @throws InterruptedException */ public static void goOnlineGame(OnlineStatus onlineMode, Room room) throws ExecutionException, InterruptedException { CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture = new CompletableFuture<>(); Game.instance = new Game(GameType.ONLINE); Loading Loading @@ -152,9 +171,7 @@ public class AppController { jsonObject.put("Game", Game.instance); jsonObject.put("History", History.instance); File save = new File(path); if (!save.exists()) { save.createNewFile(); } save.createNewFile(); // 不覆盖已有存档 Files.writeString(Path.of(path), JSON.toJSONString(jsonObject)); read(path); return true; Loading @@ -181,11 +198,6 @@ public class AppController { CompletableFuture<FrameReturnType<AppFrame>> appFuture = new CompletableFuture<>(); SwingUtilities.invokeLater(() -> { AppFrame.instance = new AppFrame(appFuture); AppFrame.instance.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { super.windowClosing(e); } }); }); FrameReturnType<AppFrame> result = appFuture.get(); AppFrame.instance.setVisible(false); Loading
src/controller/ChessClickController.java +2 −2 Changes for src/controller/ChessClickController.java: 2 added lines, 2 removed lines. Original line number Diff line number Diff line Loading @@ -94,11 +94,11 @@ public enum ChessClickController { ChessGameFrame.instance.refreshScore(1); if(Game.instance.getScoreboard()[0] >= 60){ JOptionPane.showMessageDialog(null, "红方胜利", "提示", JOptionPane.WARNING_MESSAGE); ChessGameFrame.instance.getFuture().complete(new exitGame()); ChessGameFrame.instance.exit(); } if(Game.instance.getScoreboard()[1] >= 60){ JOptionPane.showMessageDialog(null, "黑方胜利", "提示", JOptionPane.WARNING_MESSAGE); ChessGameFrame.instance.getFuture().complete(new exitGame()); ChessGameFrame.instance.exit(); } } Loading
src/view/Frame/AppFrame.java +14 −8 Changes for src/view/Frame/AppFrame.java: 14 added lines, 8 removed lines. Original line number Diff line number Diff line package view.Frame; import view.Frame.AppFrameReturnType.exitApp; import javax.swing.*; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.concurrent.CompletableFuture; public class AppFrame extends JFrame { public static AppFrame instance; private CompletableFuture<FrameReturnType<AppFrame>> future; public CompletableFuture<FrameReturnType<AppFrame>> getFuture() { return future; } private final CompletableFuture<FrameReturnType<AppFrame>> future; public AppFrame(CompletableFuture<FrameReturnType<AppFrame>> future) { this.future = future; public AppFrame(CompletableFuture<FrameReturnType<AppFrame>> appFuture) { this.future = appFuture; this.setLocation(400,0); this.setContentPane(new StartForm().rootPanel); this.setContentPane(new StartForm(this.future).rootPanel); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { future.complete(new exitApp()); super.windowClosing(e); } }); this.pack(); this.setVisible(true); } Loading
src/view/Frame/ChessGameFrame.java +4 −4 Changes for src/view/Frame/ChessGameFrame.java: 4 added lines, 4 removed lines. Original line number Diff line number Diff line Loading @@ -37,10 +37,6 @@ public class ChessGameFrame extends JFrame { private JTextArea actionHistoryArea ; public JTextArea[] score = new JTextArea[2]; public CompletableFuture<FrameReturnType<ChessGameFrame>> getFuture() { return future; } public ChessGameFrame(CompletableFuture<FrameReturnType<ChessGameFrame>> gameFuture) { this.future = gameFuture; setTitle("2022 CS109 Project Demo"); //设置标题 Loading Loading @@ -355,6 +351,10 @@ public class ChessGameFrame extends JFrame { playerListArea.append(s + "\r\n"); } public void exit(){ future.complete(new exitGame()); } public static void main(String[] args) { SwingUtilities.invokeLater(() -> { // ChessGameFrame mainFrame = new ChessGameFrame(); Loading
src/view/Frame/RoomFrame.java +1 −5 Changes for src/view/Frame/RoomFrame.java: 1 added line, 5 removed lines. Original line number Diff line number Diff line Loading @@ -18,10 +18,6 @@ public class RoomFrame extends JFrame { public static RoomFrame instance; public CompletableFuture<FrameReturnType<RoomFrame>> getFuture() { return future; } private CompletableFuture<FrameReturnType<RoomFrame>> future; private JPanel roomPane; Loading Loading @@ -77,7 +73,7 @@ public class RoomFrame extends JFrame { button.setFont(new Font("Rockwell", Font.BOLD, 20)); button.addActionListener(e -> { future.complete(new goOnline(OnlineStatus.SERVER_WAITING, null)); this.future.complete(new goOnline(OnlineStatus.SERVER_WAITING, null)); }); setPane.add(button); } Loading