Ejemplo n.º 1
0
 public Overlord(String fileName) throws IOException {
   this();
   io = new IO(this);
   io.getInfoFromFile(fileName);
   cd = new ChessDisplay(this);
   getManip();
 }
Ejemplo n.º 2
0
 public void getManip() throws IOException {
   boolean exit = false;
   while (!exit) {
     run();
     this.io = new IO(this);
     io.getInfoFromString(cd.displayMoves());
   }
 }
Ejemplo n.º 3
0
  public void run() {
    for (Behavior bee : io.getBehaviors()) {
      // Getting Pieces
      if (bee.getPiece() != null) {
        placePiece(bee.getStartPoint(), bee.getPiece());
        System.out.println(bee.toString());
      } else if (isWhitesTurn == b.get(bee.getStartPoint()).getColor()) {

        //			make into methods

        // Taking pieces
        if (this.b.get(bee.getEndPoint()) != null) {
          if (takePiece(bee.getStartPoint(), bee.getEndPoint())) {
            System.out.println(bee.toString());
          } else {
            System.err.println("Cannot take " + bee.toString());
          }
          pawnPromotion(bee.getEndPoint());
        }
        // castling
        else if (bee.getP3() != null && bee.getP4() != null) {
          if (castling(bee.getStartPoint(), bee.getEndPoint(), bee.getP3(), bee.getP4())) {
            System.out.println(bee.toString());
          } else {
            System.err.println("Cannot move " + bee.toString());
          }

        }
        // moving pieces
        else if (this.b.get(bee.getEndPoint()) == null) {
          if (movePiece(bee.getStartPoint(), bee.getEndPoint())) {
            System.out.println(bee.toString());
          } else {
            System.err.println("Cannot move " + bee.toString());
          }
          pawnPromotion(bee.getEndPoint());
        }

        isWhitesTurn = !isWhitesTurn;

        if (checkForCheckMate() && isWhitesTurn) {
          System.out.println("Checkmate. Black wins!");
        } else if (checkForCheckMate() && !isWhitesTurn) {
          System.out.println("Checkmate. White wins!");
        } else if (checkForCheckMate() && !isKingInCheck()) {
          System.out.println("StaleMate.");
        } else if (isKingInCheck()) {
          System.out.println("The King is in check");
        }

      } else {
        if (isWhitesTurn) {
          System.out.println("Its not Black's turn!");
        } else if (!isWhitesTurn) {
          System.out.println("Its not White's turn!");
        }
      }

      cd.displayBoard();
    }
  }