Loading .idea/inspectionProfiles/Project_Default.xml 0 → 100644 +8 −0 Changes for .idea/inspectionProfiles/Project_Default.xml: 8 added lines, 0 removed lines. Original line number Diff line number Diff line <component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true"> <option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,network.Server,newServerSocket" /> </inspection_tool> </profile> </component> No newline at end of file .idea/misc.xml +1 −1 Changes for .idea/misc.xml: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ <property name="JTree.lineStyle" class="java.lang.String" /> </properties> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17_PREVIEW" project-jdk-name="17" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> No newline at end of file src/controller/BulletAnim.java +2 −2 Changes for src/controller/BulletAnim.java: 2 added lines, 2 removed lines. Original line number Diff line number Diff line package controller; import model.game.Game; import model.game.Msg; import model.dataType.Msg; public class BulletAnim extends Thread{ @Override public void run() { super.run(); while (true){ for (Msg msg: Game.instance.getMsgList()){ for (Msg msg: Game.instance.msgList){ drawBullet(msg); } try { Loading src/model/game/Game.java +31 −15 Changes for src/model/game/Game.java: 31 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -9,23 +9,27 @@ import model.dataType.ChessColor; import model.dataType.GameType; import model.dataType.Msg; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Random; public class Game implements Cloneable{ public static Game instance; private Chessboard chessboard; public final Chessboard chessboard; private List<Msg> msgList = new ArrayList<>(); public final List<Msg> msgList = new ArrayList<>(); private int[] scoreboard = {0, 0}; //计分板 private final int[] scoreboard = {0, 0}; //计分板 private ChessColor currentColor = ChessColor.RED; //执棋颜色 public final GameType gameType; public final ChessColor hostColor; //服务器颜色,或者人机对战中人类颜色 public Chessboard getChessboard() { return chessboard; } Loading @@ -43,29 +47,28 @@ public class Game implements Cloneable{ } public Game(GameType gameType){ this(gameType, false); } public Game(GameType gameType, boolean setInstance){ if(setInstance) Game.instance = this; this.gameType = gameType; this.chessboard = new Chessboard(setInstance); this.hostColor = new Random().nextInt(2) == 1 ? ChessColor.RED : ChessColor.BLACK; this.chessboard = new Chessboard(); } /** * 不知道吃子第三个参数是啥的也可以送一个MoveStep */ public Step resolveStep(Step step){ Step res = null; if(step instanceof FlipStep flipStep){ res = resolveFlip(Chessboard.instance.getSquareById(flipStep.srcChessId)); res = resolveFlip(chessboard.getSquareById(flipStep.srcChessId)); } if (step instanceof MoveStep moveStep){ res = resolveMove( Chessboard.instance.getSquareById(moveStep.srcChessId), Chessboard.instance.getSquareById(moveStep.dstSquareId)); chessboard.getSquareById(moveStep.srcChessId), chessboard.getSquareById(moveStep.dstSquareId)); } if (step instanceof EatStep eatStep){ res = resolveMove( Chessboard.instance.getSquareById(eatStep.srcChessId), Chessboard.instance.getSquareById(eatStep.dstChessId)); chessboard.getSquareById(eatStep.srcChessId), chessboard.getSquareById(eatStep.dstChessId)); } if(res != null){ if(this.gameType == GameType.LOCAL_AI){ Loading Loading @@ -102,9 +105,22 @@ public class Game implements Cloneable{ @Override public Game clone() { try { return (Game) super.clone(); Game clone = (Game) super.clone(); //就这?直接反射 Field f = this.getClass().getDeclaredField("chessboard"); f.setAccessible(true); f.set(clone, this.chessboard.clone()); f.setAccessible(false); //就这? f = this.getClass().getDeclaredField("msgList"); f.setAccessible(true); f.set(clone, new ArrayList<>(this.msgList)); f.setAccessible(false); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } } No newline at end of file src/model/game/SideStack.java +6 −5 Changes for src/model/game/SideStack.java: 6 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -17,14 +17,15 @@ public class SideStack implements Serializable, Cloneable { private final ChessColor chessColor; public SideStack(ChessColor chessColor) { public SideStack(ChessColor chessColor, Chessboard parent) { this.chessColor = chessColor; ArrayList<Square> SquareList = Chessboard.getInstance().squareList; ArrayList<Square> squareList = parent.squareList; //初始化所有Square for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { Square square = new EmptySlot(SquareList.size(), new Site(this.chessColor, i, j)); SquareList.add(square); Square square = new EmptySlot( Chessboard.ID_DIVISION + squareList.size(), new Site(this.chessColor, i, j)); squareList.add(square); idGrid[i][j] = square.id; } } Loading Loading @@ -101,7 +102,7 @@ public class SideStack implements Serializable, Cloneable { public SideStack clone() { try { SideStack clone = (SideStack) super.clone(); // TODO: copy mutable state here, so the clone can't change the internals of the original clone.idGrid = this.idGrid.clone(); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(); Loading Loading
.idea/inspectionProfiles/Project_Default.xml 0 → 100644 +8 −0 Changes for .idea/inspectionProfiles/Project_Default.xml: 8 added lines, 0 removed lines. Original line number Diff line number Diff line <component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="AutoCloseableResource" enabled="true" level="WARNING" enabled_by_default="true"> <option name="METHOD_MATCHER_CONFIG" value="java.util.Formatter,format,java.io.Writer,append,com.google.common.base.Preconditions,checkNotNull,org.hibernate.Session,close,java.io.PrintWriter,printf,java.io.PrintStream,printf,network.Server,newServerSocket" /> </inspection_tool> </profile> </component> No newline at end of file
.idea/misc.xml +1 −1 Changes for .idea/misc.xml: 1 added line, 1 removed line. Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ <property name="JTree.lineStyle" class="java.lang.String" /> </properties> </component> <component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_17_PREVIEW" project-jdk-name="17" project-jdk-type="JavaSDK"> <output url="file://$PROJECT_DIR$/out" /> </component> </project> No newline at end of file
src/controller/BulletAnim.java +2 −2 Changes for src/controller/BulletAnim.java: 2 added lines, 2 removed lines. Original line number Diff line number Diff line package controller; import model.game.Game; import model.game.Msg; import model.dataType.Msg; public class BulletAnim extends Thread{ @Override public void run() { super.run(); while (true){ for (Msg msg: Game.instance.getMsgList()){ for (Msg msg: Game.instance.msgList){ drawBullet(msg); } try { Loading
src/model/game/Game.java +31 −15 Changes for src/model/game/Game.java: 31 added lines, 15 removed lines. Original line number Diff line number Diff line Loading @@ -9,23 +9,27 @@ import model.dataType.ChessColor; import model.dataType.GameType; import model.dataType.Msg; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.List; import java.util.Random; public class Game implements Cloneable{ public static Game instance; private Chessboard chessboard; public final Chessboard chessboard; private List<Msg> msgList = new ArrayList<>(); public final List<Msg> msgList = new ArrayList<>(); private int[] scoreboard = {0, 0}; //计分板 private final int[] scoreboard = {0, 0}; //计分板 private ChessColor currentColor = ChessColor.RED; //执棋颜色 public final GameType gameType; public final ChessColor hostColor; //服务器颜色,或者人机对战中人类颜色 public Chessboard getChessboard() { return chessboard; } Loading @@ -43,29 +47,28 @@ public class Game implements Cloneable{ } public Game(GameType gameType){ this(gameType, false); } public Game(GameType gameType, boolean setInstance){ if(setInstance) Game.instance = this; this.gameType = gameType; this.chessboard = new Chessboard(setInstance); this.hostColor = new Random().nextInt(2) == 1 ? ChessColor.RED : ChessColor.BLACK; this.chessboard = new Chessboard(); } /** * 不知道吃子第三个参数是啥的也可以送一个MoveStep */ public Step resolveStep(Step step){ Step res = null; if(step instanceof FlipStep flipStep){ res = resolveFlip(Chessboard.instance.getSquareById(flipStep.srcChessId)); res = resolveFlip(chessboard.getSquareById(flipStep.srcChessId)); } if (step instanceof MoveStep moveStep){ res = resolveMove( Chessboard.instance.getSquareById(moveStep.srcChessId), Chessboard.instance.getSquareById(moveStep.dstSquareId)); chessboard.getSquareById(moveStep.srcChessId), chessboard.getSquareById(moveStep.dstSquareId)); } if (step instanceof EatStep eatStep){ res = resolveMove( Chessboard.instance.getSquareById(eatStep.srcChessId), Chessboard.instance.getSquareById(eatStep.dstChessId)); chessboard.getSquareById(eatStep.srcChessId), chessboard.getSquareById(eatStep.dstChessId)); } if(res != null){ if(this.gameType == GameType.LOCAL_AI){ Loading Loading @@ -102,9 +105,22 @@ public class Game implements Cloneable{ @Override public Game clone() { try { return (Game) super.clone(); Game clone = (Game) super.clone(); //就这?直接反射 Field f = this.getClass().getDeclaredField("chessboard"); f.setAccessible(true); f.set(clone, this.chessboard.clone()); f.setAccessible(false); //就这? f = this.getClass().getDeclaredField("msgList"); f.setAccessible(true); f.set(clone, new ArrayList<>(this.msgList)); f.setAccessible(false); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(); } catch (NoSuchFieldException | IllegalAccessException e) { throw new RuntimeException(e); } } } No newline at end of file
src/model/game/SideStack.java +6 −5 Changes for src/model/game/SideStack.java: 6 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -17,14 +17,15 @@ public class SideStack implements Serializable, Cloneable { private final ChessColor chessColor; public SideStack(ChessColor chessColor) { public SideStack(ChessColor chessColor, Chessboard parent) { this.chessColor = chessColor; ArrayList<Square> SquareList = Chessboard.getInstance().squareList; ArrayList<Square> squareList = parent.squareList; //初始化所有Square for (int i = 0; i < ROW_SIZE; i++) { for (int j = 0; j < COL_SIZE; j++) { Square square = new EmptySlot(SquareList.size(), new Site(this.chessColor, i, j)); SquareList.add(square); Square square = new EmptySlot( Chessboard.ID_DIVISION + squareList.size(), new Site(this.chessColor, i, j)); squareList.add(square); idGrid[i][j] = square.id; } } Loading Loading @@ -101,7 +102,7 @@ public class SideStack implements Serializable, Cloneable { public SideStack clone() { try { SideStack clone = (SideStack) super.clone(); // TODO: copy mutable state here, so the clone can't change the internals of the original clone.idGrid = this.idGrid.clone(); return clone; } catch (CloneNotSupportedException e) { throw new AssertionError(); Loading