package ru.matevosyan.Figures;

import ru.matevosyan.exceptions.FigureNotFoundException;
import ru.matevosyan.exceptions.ImpossibleMoveException;
import ru.matevosyan.models.Cell;
import ru.matevosyan.models.Figure;

/**
 * Created Bishop as one of figures.
 * Created on 29.01.2017.
 * @since 1.0
 * @author Matevosyan Vardan
 * @version 1.0
 */

public class Bishop extends Figure {

    /**
     * Bishop name.
     */

    private final String name = "Bishop";

    /**
     * Bishop constructor invoke parent constructor which assign Cell position.
     * @param position Bishop position
     */

    public Bishop(Cell position) {
      super(position);
    }

    /**
     * Method way find the bishop movement and assign to Cell array which is returning in the end.
     * And we get all the way that bishop is getting.
     * @param dist the way that we want to get.
     * @return bishopWay that is actually array of cell or array of movement.
     * @throws ImpossibleMoveException throw when move is imposable.
     */

    @Override
    public Cell[] way(Cell dist) throws ImpossibleMoveException {

        Cell[] bishopWay = new Cell[7];
        int i = 0;

        if (Math.abs(dist.getX() - this.position.getX()) == Math.abs(dist.getY() - this.position.getY())) {

            /**
             * Get Cell distance X and Y getting from passing to method way.
             */

            int distX = dist.getX();
            int distY = dist.getY();

            /**
             * Get Cell current position X and Y getting from passing to method way.
             */

            int currentDistX = this.position.getX();
            int currentDistY = this.position.getY();

            /**
             * BishopStepsX = |distX-sourceX|-> it is figure steps.
             */

            int bishopStepsX = Math.abs(distX - currentDistX);

            /**
             * BishopStepsY = |distY-sourceY|-> it is figure steps.
             */

            int bishopStepsY = Math.abs(distY - currentDistY);

            /**
             * Example.
             * if dist = 0.7 from 6.1 then we go from 6.1  when distX < sourceX then increment distX while dist = source
             * and else distX > sourceX then decrement distX while dist = source and the same way we can use distY
             */

            if (bishopStepsX != 0 & bishopStepsY != 0) {
                do {
                    if (distX < currentDistX & distY < currentDistY) {
                        distX++;
                        distY++;
                        bishopWay[i++] = dist;
                    } else if (distX < currentDistX & distY > currentDistY) {
                        distX++;
                        distY--;
                        bishopWay[i++] = dist;
                    } else if (distX > currentDistX & distY > currentDistY) {
                        distX--;
                        distY--;
                        bishopWay[i++] = dist;
                    } else if (distX > currentDistX & distY < currentDistY) {
                        distX--;
                        distY++;
                        bishopWay[i++] = dist;
                    }
                } while (distX != currentDistX & distY != currentDistY);
            } else {
                throw new ImpossibleMoveException("You can't move that way!!!");
            }

        }
        return bishopWay;
    }

    /**
     * Override clone method in Figure class which is actually abstract.
     * @param destination the way that we want to get.
     * @return new bishop instance.
     * @throws FigureNotFoundException that is men that clone can not find figure in destination position.
     */

    @Override
    public Figure clone(Cell destination) throws FigureNotFoundException {
        return new Bishop(destination);
    }

}

@@ -1146,16 +1146,54 @@
 ell%5B7%5D;%0A
+        Cell bishopStep = new Cell();%0A
         
@@ -2511,39 +2511,56 @@
                 
-d
+b
 is
+hopStep.se
 tX
+(
 ++
+distX)
 ;%0A              
@@ -2561,39 +2561,56 @@
                 
-d
+b
 is
+hopStep.se
 tY
+(
 ++
+distY)
 ;%0A              
@@ -2628,36 +2628,42 @@
 ishopWay%5Bi++%5D = 
-dist
+bishopStep
 ;%0A              
@@ -2754,15 +2754,32 @@
     
-d
+b
 is
+hopStep.se
 tX
+(
 ++
+distX)
 ;%0A  
@@ -2792,39 +2792,56 @@
                 
-d
+b
 is
+hopStep.se
 tY
+(
 --
+distY)
 ;%0A              
@@ -2859,36 +2859,42 @@
 ishopWay%5Bi++%5D = 
-dist
+bishopStep
 ;%0A              
@@ -2973,39 +2973,56 @@
                 
-d
+b
 is
+hopStep.se
 tX
+(
 --
+distX)
 ;%0A              
@@ -3035,15 +3035,32 @@
     
-d
+b
 is
+hopStep.se
 tY
+(
 --
+distY)
 ;%0A  
@@ -3090,36 +3090,42 @@
 ishopWay%5Bi++%5D = 
-dist
+bishopStep
 ;%0A              
@@ -3216,15 +3216,32 @@
     
-d
+b
 is
+hopStep.se
 tX
+(
 --
+distX)
 ;%0A  
@@ -3266,15 +3266,32 @@
     
-d
+b
 is
+hopStep.se
 tY
+(
 ++
+distY)
 ;%0A  
@@ -3329,20 +3329,26 @@
 %5Bi++%5D = 
-dist
+bishopStep
 ;%0A      

add Cell variable bishopStep and assign X and Y using setX and setY after assign to bishop way array to return it