Commit 4a7480a5 authored by lynn's avatar lynn
Browse files

updates

parent 4939e568
Loading
Loading
Loading
Loading
+6 −49
Original line number Diff line number Diff line
@@ -2,7 +2,6 @@ package chessComponent;

import controller.ClickController;
import model.ChessColor;
import model.ChessType;
import model.ChessboardPoint;

import java.awt.*;
@@ -11,52 +10,11 @@ import java.awt.*;
 * 表示棋盘上非空棋子的格子,是所有非空棋子的父类
 */
public class ChessComponent extends SquareComponent{
    protected final ChessColor chessColor;
    protected String name;// 棋子名字:例如 兵,卒,士等

    protected final ChessType chessType;

    protected boolean alive;

    protected ChessComponent(ChessboardPoint chessboardPoint, Point location,
                             ChessColor chessColor, ChessType chessType, ClickController clickController, int size) {
        super(chessboardPoint, location, clickController, size);
        this.chessColor = chessColor;
        this.chessType = chessType;
        this.alive = true;
    }

    public ChessColor getChessColor() {
        return chessColor;
    }

    public ChessType getChessType() {
        return chessType;
    }

    public boolean isAlive() {
        return alive;
    }

    public void kill(){
        this.alive = false;
    protected ChessComponent(ChessboardPoint chessboardPoint, Point location, ChessColor chessColor, ClickController clickController, int size) {
        super(chessboardPoint, location, chessColor, clickController, size);
    }

    //TODO: complete deduce
    public static String deduceChessName(ChessColor chessColor, ChessType chessType) {
        switch (chessColor) {
            case RED -> switch (chessType) {
                case GENERAL -> '帅';
                case ADVISOR -> '士';

            }
            case BLACK ->
        }
    }

    private String deduceChessName() {
        return deduceChessName(this.chessColor, this.chessType);
    }

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
@@ -71,7 +29,7 @@ public class ChessComponent extends SquareComponent {
            //绘制棋子文字
            g.setColor(this.getChessColor().getColor());
            g.setFont(CHESS_FONT);
            g.drawString(this.deduceChessName(), this.getWidth() / 4, this.getHeight() * 2 / 3);
            g.drawString(this.name, this.getWidth() / 4, this.getHeight() * 2 / 3);

            //绘制棋子被选中时状态
            if (isSelected()) {
@@ -82,5 +40,4 @@ public class ChessComponent extends SquareComponent {
            }
        }
    }

}