package ru.job4j.figure;

import ru.job4j.game.*;

/**.
* Chapter_002
* Task 2.9.2
* Create class Bishop
*
* @author Anton Vasilyuk
* @version 1.0
* @since 0.1
*/

public class Bishop extends Figure {

    /**.
     * Constructor for class Bishop
     * @param cellPosition is position figure
     */
    public Bishop(Cell cellPosition) {
        super(cellPosition);
    }

    /**.
     * Method for check validate way this figure
     * @param cell point
     * @return array from cell
     */
    @Override
    public Cell[] way(Cell cell) throws ImposibleMoveException {

        Board board = new Board();
        Cell[] cells;
		Figure[] figure = board.getFigures();
        board.fillFigure();

        int srcRow = this.cellPosition.getRow();
        int srcCol = this.cellPosition.getCol();
        int disRow = cell.getRow();
        int disCol = cell.getCol();
        int line = figure.length;

        if (srcRow == disRow && srcCol == disCol) {
			throw new ImposibleMoveException("It cell is busy, make outher choice");
        }
        if (disRow > 7 || disRow < 0 || disCol > 7 || disCol < 0) {
            throw new ImposibleMoveException("incorrect choice, change outher cell");
        } else if (srcRow == disRow && srcCol == disCol) {
            throw new ImposibleMoveException("this figure nowhere walk, change correct choice");
        } else if (srcRow == disRow && srcCol != disCol) {
            cells = new Cell[Math.abs(disCol - srcCol)];
            if (srcCol < disCol) {
                for (int i = 0; i < Math.abs(disCol - srcCol); i++) {
                    cells[i] = new Cell(srcRow, srcCol + i + 1);
                }
            } else {
                for (int i = 0; i < Math.abs(disCol - srcCol); i++) {
                    cells[i] = new Cell(srcRow, srcCol - i - 1);
                }
            }
            return cells;
        } else if (srcRow != disRow && srcCol == disCol) {
            cells = new Cell[Math.abs(disRow - srcRow)];
            if (srcRow < disRow) {
                for (int i = 0; i < Math.abs(disRow - srcRow); i++) {
                    cells[i] = new Cell(srcRow + i + 1, srcCol);
                }
            } else {
                for (int i = 0; i < Math.abs(disCol - srcCol); i++) {
                    cells[i] = new Cell(srcRow - i - 1, srcCol);
                }
            }
            return cells;
        } else {
            System.out.println("You destroy my programm");
            return cells = null;
        }
    }
}
@@ -863,32 +863,78 @@
 l.getCol();%0A
- 
+%09%09int positionRow = 0;%0A%09%09int positionCol = 0;%0A
        
+ 
 int line = f
@@ -936,21 +936,9 @@
 e = 
-figure.length
+0
 ;%0A%0A 
@@ -1229,38 +1229,36 @@
 ell%22);%0A        %7D
- else 
+%0A%0A%09%09
 if (srcRow == di
@@ -1383,38 +1383,36 @@
 ice%22);%0A        %7D
- else 
+%0A%0A%09%09
 if (srcRow == di
@@ -1416,26 +1416,26 @@
  disRow 
-&&
+%7C%7C
  srcCol 
 != disCo
@@ -1426,17 +1426,17 @@
  srcCol 
-!
+=
 = disCol
@@ -1443,37 +1443,41 @@
 ) %7B%0A
-            cells = new Cell%5B
+%09%09%09if (srcRow == disRow) %7Bline = 
 Math
@@ -1497,31 +1497,22 @@
  srcCol)
-%5D;%0A            
+;%7D%0A%09%09%09
 if (srcC
@@ -1514,17 +1514,18 @@
 (srcCol 
-%3C
+==
  disCol)
@@ -1530,44 +1530,14 @@
 l) %7B
-%0A                for (int i = 0; i %3C
+line =
  Mat
@@ -1549,38 +1549,24 @@
 (dis
-Col
+Row
  - src
-Col); i++) %7B%0A        
+Row);%7D%0A
     
@@ -1570,35 +1570,32 @@
            cells
-%5Bi%5D
  = new Cell(srcR
@@ -1593,906 +1593,402 @@
 Cell
-(srcRow, srcCol + i + 1);%0A                %7D%0A            %7D else %7B%0A                for (int i = 0; i %3C Math.abs(disCol - srcCol); i++) %7B%0A                    cells%5Bi%5D = new Cell(srcRow,
+%5Bline%5D;%0A%09%09%09int rMove = disRow %3E srcRow ? 1 : disRow %3C
  src
-Col - i - 1);%0A                %7D%0A            %7D%0A            return cells;%0A        %7D else if (srcRow != disRow && srcCol == disCol) %7B%0A            cells = new Cell%5BMath.abs(disRow - srcRow)%5D;%0A            if (srcRow %3C disRow) %7B%0A                for (int i = 0; i %3C Math.abs(disRow - srcRow); i++) %7B%0A                    cells%5Bi%5D = new Cell(srcRow + i + 1, srcCol);%0A                %7D%0A            %7D else %7B%0A                for (int i = 0; i %3C Math.abs(disCol - srcCol); i++) %7B%0A                    cells%5Bi%5D = new Cell(srcRow - i - 1, srcCol);%0A                %7D%0A            %7D%0A            return cells;%0A        %7D else %7B%0A            System.out.println(%22You destroy my programm%22);%0A            return cells = null;%0A        %7D%0A    
+Row ? -1 : 0;%0A%09%09%09int cMove = disCol %3E srcCol ? 1 : disCol %3C srcCol ? -1 : 0;%0A%09%09%09for (int i = 0; i %3C line; i++) %7B%0A%09%09%09%09positionRow = positionRow + rMove;%0A%09%09%09%09positionCol = positionCol + cMove;%0A%09%09%09%09cells%5Bi%5D = new Cell(positionRow, positionCol);%0A%09%09%09%7D%0A%09%09%7D else %7B%0A%09%09%09throw new ImposibleMoveException(%22don't right choise%22);%0A%09%09%7D%0A%09%09return cells;%0A%09
 %7D%0A%7D

add file for chapter_002_2.9.2