Package tools

Examples of tools.Index


            break;
          }
        }
        if (p!=null) {
          String notation = board.coordinatesToNotation(p.getRow(), p.getCol());
          Index idx = notationToPieceLoc(notation);
          g2.drawImage(img, idx.getX(), idx.getY(), this);
        }
      }
    }
View Full Code Here


     */
    public void movePiece(Board board, Move move, Player player, String src, String dest) {
      //get piece to move
      Piece p = board.notationToPiece(src);
      //array coordinates for new destination
    Index newLoc = board.notationToIndex(dest);
    //remove captured piece from the board
    board.removePiece(newLoc.getX(), newLoc.getY());
    p.setRow(newLoc.getX()); //change piece row
    p.setCol(newLoc.getY()); //change piece column
    //place source and destination square to history of moves
    if (player.getSide()==0) { //if white
      //add white piece move to history
      move.getHistoryOfMoves().addWhiteMove(src, dest);
    } else if (player.getSide()==1) { //if black
View Full Code Here

    /**
     * Paint defined square on the board.
     */
    public void paintSquare(String notation, Color color) {
      //get piece coordinates
      Index squareLoc = notationToPieceLoc(notation);

      //redraw square color
    getG1().setColor(color);
    getG1().fillRect(squareLoc.getX(), squareLoc.getY(), 50, 50);
    }
View Full Code Here

      //vertical square's left corner location possibilities
      int[] rowCoord = {0, (height/8)-1, 2*(height/8)-1, 3*(height/8)-1, 4*(height/8)-1,
      5*(height/8)-1, 6*(height/8)-1, 7*(height/8)-1};
     
      Index loc, gLoc = new Index(0, 0);
      //get square location
      loc = new Board().notationToIndex(notation);
      //get upper left corner location
      gLoc.setX(columnCoord[loc.getY()]);
      gLoc.setY(rowCoord[loc.getX()]);
     
      return gLoc;
    }
View Full Code Here

      }
    Piece piece = board.notationToPiece(srcSq);
    //get all movements that are allowed for the selected piece
    ArrayList<ArrayList<Integer>> legalMoves = move.possiblePieceMoves(piece, false);
    //array coordinates for new destination
    Index newLoc = board.notationToIndex(destSq);
    //find out if destination location is included in the legal moves list
    ArrayList<Integer> x = legalMoves.get(0); //list of row numbers
    ArrayList<Integer> y = legalMoves.get(1); //list of column numbers
    ListIterator<Integer> xList = x.listIterator()//row iterator
    ListIterator<Integer> yList = y.listIterator()//column iterator
    int xL, yL;
    while (xList.hasNext() && yList.hasNext()) { //while lists have coordinates
      //listiterator next() method doesn't work inside if statement -> assign to variables
      xL = xList.next();
      yL = yList.next();
      if (newLoc.getX()==xL && newLoc.getY()==yL) { //legal move
        return true;
      }
    } 
    return false;
    }
View Full Code Here

      break;
    default:
      break;
    }
   
    Index index = new Index(x, y);
    return index;
  }
View Full Code Here

   * @return Piece
   */
  public Piece notationToPiece(String notation) {
    boolean pieceFound = false;
    //find the piece based on the source square notation.
    Index srcCrd = notationToIndex(notation); //convert notation to array coordinates
    ArrayList<Piece> pieces = getPieces(); //save all pieces into a arraylist
    Piece piece = null;
    //loop arraylist of pieces
    findPiece: for (Piece p : pieces) {
        piece = p;
        //if piece row and column mathes given piece destination
        if (piece.getRow() == srcCrd.getX() && piece.getCol() == srcCrd.getY()) {
          pieceFound = true;
          break findPiece; //move out of the loop
        }
    }
    if (pieceFound) {
View Full Code Here

        //make sure the piece is owned by the player
        if (piece.getColor()==player.getSide()) {
          //get all movements that are allowed for the selected piece
          ArrayList<ArrayList<Integer>> legalMoves = possiblePieceMoves(piece, false);
          //array coordinates for new destination
          Index newLoc = getBoard().notationToIndex(destSq);
          //find out if destination location is included in the legal moves list
          ArrayList<Integer> x = legalMoves.get(0); //list of row numbers
          ArrayList<Integer> y = legalMoves.get(1); //list of column numbers
          ListIterator<Integer> xList = x.listIterator()//row iterator
          ListIterator<Integer> yList = y.listIterator()//column iterator
          int xL, yL;
          while (xList.hasNext() && yList.hasNext()) { //while lists have coordinates
            //listiterator next() method doesn't work inside if statement -> assign to variables
            xL = xList.next();
            yL = yList.next();
            if (newLoc.getX()==xL && newLoc.getY()==yL) { //legal move
              getBoard().removePiece(newLoc.getX(), newLoc.getY()); //remove captured piece from the board
              piece.setRow(newLoc.getX()); //change piece row
              piece.setCol(newLoc.getY()); //change piece column
//              board.updateGameState(); //populate the board with new location of pieces.
              //place source and destination square to history of moves
              if (player.getSide()==0) { //if white
                getHistoryOfMoves().addWhiteMove(srcSq, destSq); //add white piece move to history
              } else if (player.getSide()==1) { //if black
View Full Code Here

   * Returns true if the piece is found from the given location.
   * @param notation
   * @return boolean
   */
  public boolean isPieceOnSquare(String notation) {
    Index index = getBoard().notationToIndex(notation);
    Piece piece;
    for (Piece p : getBoard().getPieces()) {
        piece = p;
        if (piece.getRow() == index.getX() && piece.getCol() == index.getY()) {
          return true;
        }
    }
    return false; //piece not found
  }
View Full Code Here

   * @param notation
   * @param color
   * @return boolean
   */
  public boolean isPieceOnSquare(String notation, int color) {
    Index index = getBoard().notationToIndex(notation);
    for (Piece p : getBoard().getPieces()) {
        if (p.getColor() == color) {
          if (p.getRow() == index.getX() && p.getCol() == index.getY()) {
            return true;
          }
        }
    }
    return false;
View Full Code Here

TOP

Related Classes of tools.Index

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.