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

(undone-3)feat(model interfaces)

parent 61cdd812
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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" project-jdk-name="corretto-17" project-jdk-type="JavaSDK">
    <output url="file://$PROJECT_DIR$/out" />
  </component>
</project>
 No newline at end of file
+19 −4
Original line number Diff line number Diff line
package controller;

import model.game.Game;
import model.game.Msg;

public class BulletAnim {
    
    public void draw(Msg msg){
public class BulletAnim extends Thread{
    @Override
    public void run() {
        super.run();
        while (true){
            for (Msg msg: Game.instance.getMsgList()){
                drawBullet(msg);
            }
            try {
                sleep(50);
            } catch (InterruptedException ignored) {
                break;
            }
        }
    }

    public void drawBullet(Msg msg){
        //TODO: drawBullet
    }
}
+13 −11
Original line number Diff line number Diff line
@@ -10,6 +10,8 @@ import java.util.*;
 * 这个类表示棋盘组建,其包含:
 * Square[][]: 4*8个方块格子组件
 */

//TODO: Refactor into id mode
public class Chessboard implements Serializable, Cloneable {
    /**
     * 不彻底的单例
@@ -21,7 +23,7 @@ public class Chessboard implements Serializable, Cloneable {

    public static final int ID_DIVISION = ROW_SIZE * COL_SIZE;

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

    //两个亡子堆->亡子堆组
    private SideStack[] sideStacks = new SideStack[]{
@@ -52,9 +54,9 @@ public class Chessboard implements Serializable, Cloneable {
        Collections.shuffle(paramsList);

        //每个棋子初始化的时候,从末尾拿元组作为参数,并移除那个元组,如同出栈
        for (int i = 0; i < squares.length; i++) {
            squares[i] = new Square[COL_SIZE];
            for (int j = 0; j < squares[i].length; j++) {
        for (int i = 0; i < idGrid.length; i++) {
            idGrid[i] = new Square[COL_SIZE];
            for (int j = 0; j < idGrid[i].length; j++) {
                Chess chess;
                Tuple2<ChessColor, ChessType> params = paramsList.get(paramsList.size() - 1);
                chess = new Chess(new GridPoint(i, j), params._1, params._2);
@@ -71,8 +73,8 @@ public class Chessboard implements Serializable, Cloneable {
        instance = instance1;
    }

    public Square[][] getSquares() {
        return squares;
    public Square[][] getIdGrid() {
        return idGrid;
    }

    /**
@@ -80,7 +82,7 @@ public class Chessboard implements Serializable, Cloneable {
     * @param gridPoint 棋盘坐标
     */
    public Square getSquareAtPoint(GridPoint gridPoint) {
        return squares[gridPoint.getY()][gridPoint.getX()];
        return idGrid[gridPoint.getY()][gridPoint.getX()];
    }

    /**
@@ -124,7 +126,7 @@ public class Chessboard implements Serializable, Cloneable {
     */
    public void putChessOnBoard(Square square) {
        int row = square.getGridPoint().getY(), col = square.getGridPoint().getX();
        squares[row][col] = square;
        idGrid[row][col] = square;
    }

    /**
@@ -146,9 +148,9 @@ public class Chessboard implements Serializable, Cloneable {

        //Set squares' references
        int row1 = chess1.getGridPoint().getY(), col1 = chess1.getGridPoint().getX();
        squares[row1][col1] = chess1;
        idGrid[row1][col1] = chess1;
        int row2 = square2.getGridPoint().getY(), col2 = square2.getGridPoint().getX();
        squares[row2][col2] = square2;
        idGrid[row2][col2] = square2;

        //重绘
        ChessboardCom.getInstance().getSquareComAtPoint(chess1.getGridPoint()).repaint();
@@ -167,7 +169,7 @@ public class Chessboard implements Serializable, Cloneable {
    public Chessboard clone() {
        try {
            Chessboard clone = (Chessboard) super.clone();
            clone.squares = this.squares.clone();
            clone.idGrid = this.idGrid.clone();
            clone.sideStacks = this.sideStacks.clone();
            return clone;
        } catch (CloneNotSupportedException e) {
+1 −1
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ public class Game implements Cloneable{
    }

    public boolean resolveStep(Step step){
        //TODO resolveStep
        //TODO resolveStep of every level
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class ChessboardCom extends JComponent {
            for (int j = 0; j < Chessboard.COL_SIZE; j++) {
                GridPoint gridPoint = new GridPoint(i, j);
                putChessOnBoard(new SquareCom(
                        gridPoint, evalPoint(gridPoint), SQUARE_SIZE, spacingLength, true
                        gridPoint, evalPoint(gridPoint), SQUARE_SIZE, spacingLength, ChessColor.NONE
                ));
            }
        }
Loading