Commit c8b6fd13 authored by 刘家荣's avatar 刘家荣 💬
Browse files

000000

parent fdc79157
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ public class Chessboard implements Serializable, Cloneable {

    private Square[][] idGrid = new Square[ROW_SIZE][COL_SIZE];  //方格子列表

    private ArrayList<Square> squareList;

    //两个亡子堆->亡子堆组
    private SideStack[] sideStacks = new SideStack[]{
            new SideStack(ChessColor.BLACK),
@@ -36,8 +38,7 @@ public class Chessboard implements Serializable, Cloneable {
     */
    public Chessboard() {
        Random random = new Random();
        //此列表的元素是元组,每个元组存储的是对应棋子的部分参数(颜色和类别)
        ArrayList<Tuple2<ChessColor, ChessType>> paramsList = new ArrayList<>();
        squareList = new ArrayList<>(36);
        for (ChessColor chessColor : new ChessColor[]{ChessColor.BLACK, ChessColor.RED}) {
            for (ChessType chessType : ChessType.values()) {
                int cnt = switch (chessType) {
@@ -46,9 +47,12 @@ public class Chessboard implements Serializable, Cloneable {
                    default -> 2;
                };
                for (int i = 0; i < cnt; i++) {
                    paramsList.add(new Tuple2<>(chessColor, chessType));
                    squareList.add(new Chess(new GridPoint(0,0), chessColor, chessType));
                }
            }
        }
        for (int i = 0; i < ROW_SIZE * COL_SIZE * 2; i++) {
            squareList.add(new Square(new GridPoint(0,0)));
        }
        //打乱该列表
        Collections.shuffle(paramsList);
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ package model.game;
 * 注意一般表示网格坐标时,按照二维数组的习惯是先行后列
 */
public class GridPoint{
    private int x, y;
    protected final int x, y;

    /**
     * @param y: row
+20 −0
Original line number Diff line number Diff line
package model.game;

public class Location extends GridPoint{
    private final Plate plate;

    /**
     * @param plate: plate
     * @param y: row
     * @param x: col
     */
    public Location(Plate plate, int y, int x) {
        super(y,x);
        this.plate = plate;
    }

    @Override
    public String toString() {
        return String.format("GridPoint{Plate: %s, y: %d, x: %d}", this.plate.name(), this.y, this.x);
    }
}
+8 −0
Original line number Diff line number Diff line
package model.game;

/**
 * 颜色,但是是特指阵营颜色
 */
public enum Plate {
     MAIN, BLACK_SIDE_STACK, RED_SIDE_STACK;
}