Commit 4939e568 authored by lynn's avatar lynn
Browse files

Merge remote-tracking branch 'origin/main'

# Conflicts:
#	src/chessComponent/ChessComponent.java
#	src/view/Chessboard.java
parents 4b617feb 3a459e8b
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
# BugChess

***
BugChess是在椰树集团精神下开创的一个鲜榨项目,是一次探索与定义下一代翻棋游戏的伟大尝试
BugChess是一个在椰树精神的指导下开创的一个鲜榨项目,是一次探索与定义下一代翻棋游戏的伟大尝试
***

## 项目配置
+47 −7
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package chessComponent;

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

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

    protected final ChessType chessType;

    protected boolean alive;

    protected ChessComponent(ChessboardPoint chessboardPoint, Point location,
                             ChessColor chessColor, ClickController clickController, int size) {
        super(chessboardPoint, location, chessColor, clickController, size);
                             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;
    }

    //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);
    }
//    public ChessComponent(){}

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

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

}
+1 −0
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package chessComponent;

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

import java.awt.*;
+2 −7
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ public abstract class SquareComponent extends JComponent {
     * selected: 表示这个棋子是否被选中
     */
    private ChessboardPoint chessboardPoint;
    protected final ChessColor chessColor;

    protected boolean isReversal;
    private boolean selected;

@@ -36,12 +36,11 @@ public abstract class SquareComponent extends JComponent {
     */
    private final ClickController clickController;

    protected SquareComponent(ChessboardPoint chessboardPoint, Point location, ChessColor chessColor, ClickController clickController, int size) {
    protected SquareComponent(ChessboardPoint chessboardPoint, Point location, ClickController clickController, int size) {
        enableEvents(AWTEvent.MOUSE_EVENT_MASK);
        setLocation(location);
        setSize(size, size);
        this.chessboardPoint = chessboardPoint;
        this.chessColor = chessColor;
        this.selected = false;
        this.clickController = clickController;
        this.isReversal = false;
@@ -69,10 +68,6 @@ public abstract class SquareComponent extends JComponent {
        this.chessboardPoint = chessboardPoint;
    }

    public ChessColor getChessColor() {
        return chessColor;
    }

    public boolean isSelected() {
        return selected;
    }
+10 −7
Original line number Diff line number Diff line
package controller;


import chessComponent.SquareComponent;
import chessComponent.ChessComponent;
import chessComponent.EmptySlotComponent;
import chessComponent.SquareComponent;
import model.ChessColor;
import view.ChessGameFrame;
import view.Chessboard;
@@ -47,14 +48,17 @@ public class ClickController {
     */

    private boolean handleFirst(SquareComponent squareComponent) {
        if (!squareComponent.isReversal()) {
            squareComponent.setReversal(true);
            System.out.printf("onClick to reverse a chess [%d,%d]\n", squareComponent.getChessboardPoint().getX(), squareComponent.getChessboardPoint().getY());
            squareComponent.repaint();
        if (!(squareComponent instanceof ChessComponent chessComponent)) {
            return false;
        }
        if (!chessComponent.isReversal()) {
            chessComponent.setReversal(true);
            System.out.printf("onClick to reverse a chess [%d,%d]\n", chessComponent.getChessboardPoint().getX(), chessComponent.getChessboardPoint().getY());
            chessComponent.repaint();
            chessboard.clickController.swapPlayer();
            return false;
        }
        return squareComponent.getChessColor() == chessboard.getCurrentColor();
        return chessComponent.getChessColor() == chessboard.getCurrentColor();
    }

    /**
@@ -63,7 +67,6 @@ public class ClickController {
     */

    private boolean handleSecond(SquareComponent squareComponent) {

        //没翻开或空棋子,进入if
        if (!squareComponent.isReversal()) {
            //没翻开且非空棋子不能走
Loading