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

fix(initAllChessOnBoard): Fixed random init & Commented all XXXChessComponent Files

(to make sure the program can, at least, run)
parent 682ed7c3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
<component name="libraryTable">
  <library name="io.vavr" type="repository">
    <properties maven-id="io.vavr:vavr:0.10.4" />
    <CLASSES>
      <root url="jar://$MAVEN_REPOSITORY$/io/vavr/vavr/0.10.4/vavr-0.10.4.jar!/" />
      <root url="jar://$MAVEN_REPOSITORY$/io/vavr/vavr-match/0.10.4/vavr-match-0.10.4.jar!/" />
    </CLASSES>
    <JAVADOC />
    <SOURCES />
  </library>
</component>
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -7,5 +7,6 @@
    </content>
    <orderEntry type="inheritedJdk" />
    <orderEntry type="sourceFolder" forTests="false" />
    <orderEntry type="library" name="io.vavr" level="project" />
  </component>
</module>
 No newline at end of file
+19 −19
Original line number Diff line number Diff line
package chessComponent;

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

import java.awt.*;

public class AdvisorChessComponent extends AllChessComponents{
    protected AdvisorChessComponent(ChessboardPoint chessboardPoint, Point location,
                                    ChessColor chessColor, ClickController clickController, int size) {
        super(chessboardPoint, location, chessColor, clickController, size);
        if (this.getChessColor() == ChessColor.RED) {
            name = "仕";
        } else {
            name = "士";
        }
    }
}
//package chessComponent;
//
//import controller.ClickController;
//import model.ChessColor;
//import model.ChessboardPoint;
//
//import java.awt.*;
//
//public class AdvisorChessComponent extends AllChessComponents{
//    protected AdvisorChessComponent(ChessboardPoint chessboardPoint, Point location,
//                                    ChessColor chessColor, ClickController clickController, int size) {
//        super(chessboardPoint, location, chessColor, clickController, size);
//        if (this.getChessColor() == ChessColor.RED) {
//            name = "仕";
//        } else {
//            name = "士";
//        }
//    }
//}
+73 −73
Original line number Diff line number Diff line
package chessComponent;

import controller.ClickController;
import model.ChessColor;
import model.ChessboardPoint;
import java.awt.*;

// todo: use polymorphism to write all chess components
/*  思路:用 0~13 分别代表各个棋子
 *   创建 enum 类
 *   问题:enum 不能调用ChessComponent的constructor
 *       enum 静态构造可行吗?
 */
    public class AllChessComponents extends ChessComponent {

/*          用 enum 列出棋子种类,
*           chessNum 对应每种棋子,
*           便于在 Chessboard 用 random 随机初始化棋子位置
* */
       public enum allChessComponent {Soldier, Horse, Chariot, Minister, Advisor, General, Cannon}

    public int getChessNum() {
        return chessNum;
    }

    public void setChessNum(int chessNum) {
        this.chessNum = chessNum;
    }

    private int chessNum;

//      todo:  确定输入 chessNum 的位置

        public static allChessComponent setChess (int chessNum) {
            // 或许可以在ChessComponent 和 SquareComponent 里写空的 constructor
           allChessComponent chess = allChessComponent.Soldier;
            switch (chessNum){
                case 0:
                    // enum 不能向下转型
                        chess = allChessComponent.Soldier;
                        break;
                case 1:
                    chess = allChessComponent.Horse;
                    break;
                case 2:
                    chess = allChessComponent.Chariot;
                    break;
                case 3:
                    chess = allChessComponent.Minister;
                    break;
                case 4:
                    chess = allChessComponent.Advisor;
                    break;
                case 5:
                    chess = allChessComponent.General;
                    break;
                case 6:
                    chess = allChessComponent.Cannon;
                    break;
            }
            return chess;
        }
        public AllChessComponents(ChessboardPoint chessboardPoint, Point location, ChessColor chessColor,
                                  ClickController clickController, int size) {
            super(chessboardPoint, location, chessColor, clickController, size);
            // todo: 确定 enum 出的每个棋子都关联到各自的类
            this.name = setChess(getChessNum()).name();
        }
        // void constructor
//        public AllChessComponents(){}
    }

//package chessComponent;
//
//import controller.ClickController;
//import model.ChessColor;
//import model.ChessboardPoint;
//import java.awt.*;
//
//
///*  思路:用 0~13 分别代表各个棋子
// *   创建 enum 类
// *   问题:enum 不能调用ChessComponent的constructor
// *       enum 静态构造可行吗?
// */
//    public class AllChessComponents extends ChessComponent {
//
///*          用 enum 列出棋子种类,
//*           chessNum 对应每种棋子,
//*           便于在 Chessboard 用 random 随机初始化棋子位置
//* */
//       public enum allChessComponent {Soldier, Horse, Chariot, Minister, Advisor, General, Cannon}
//
//    public int getChessNum() {
//        return chessNum;
//    }
//
//    public void setChessNum(int chessNum) {
//        this.chessNum = chessNum;
//    }
//
//    private int chessNum;
//
//
//
//        public static allChessComponent setChess (int chessNum) {
//            // 或许可以在ChessComponent 和 SquareComponent 里写空的 constructor
//           allChessComponent chess = allChessComponent.Soldier;
//            switch (chessNum){
//                case 0:
//                    // enum 不能向下转型
//                        chess = allChessComponent.Soldier;
//                        break;
//                case 1:
//                    chess = allChessComponent.Horse;
//                    break;
//                case 2:
//                    chess = allChessComponent.Chariot;
//                    break;
//                case 3:
//                    chess = allChessComponent.Minister;
//                    break;
//                case 4:
//                    chess = allChessComponent.Advisor;
//                    break;
//                case 5:
//                    chess = allChessComponent.General;
//                    break;
//                case 6:
//                    chess = allChessComponent.Cannon;
//                    break;
//            }
//            return chess;
//        }
//        public AllChessComponents(ChessboardPoint chessboardPoint, Point location, ChessColor chessColor,
//                                  ClickController clickController, int size) {
//            super(chessboardPoint, location, chessColor, clickController, size);
//            // todo: 确定 enum 出的每个棋子都关联到各自的类
//            this.name = setChess(getChessNum()).name();
//        }
//        // void constructor
////        public AllChessComponents(){}
//    }
//
//
+19 −19
Original line number Diff line number Diff line
package chessComponent;

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

import java.awt.*;

public class CannonChessComponent extends  AllChessComponents{
    protected CannonChessComponent(ChessboardPoint chessboardPoint, Point location,
                                   ChessColor chessColor, ClickController clickController, int size) {
        super(chessboardPoint, location, chessColor, clickController, size);
        if (this.getChessColor() == ChessColor.RED) {
            name = "炮";
        } else {
            name = "砲";
        }
    }
}
//package chessComponent;
//
//import controller.ClickController;
//import model.ChessColor;
//import model.ChessboardPoint;
//
//import java.awt.*;
//
//public class CannonChessComponent extends  AllChessComponents{
//    protected CannonChessComponent(ChessboardPoint chessboardPoint, Point location,
//                                   ChessColor chessColor, ClickController clickController, int size) {
//        super(chessboardPoint, location, chessColor, clickController, size);
//        if (this.getChessColor() == ChessColor.RED) {
//            name = "炮";
//        } else {
//            name = "砲";
//        }
//    }
//}
Loading