package ru.job4j.chess.model;

import ru.job4j.chess.exceptions.ImpossibleMoveException;

/**
 * This class describes figure queen of the chess.
 *
 * @author Kucykh Vasily (mailto:basil135@mail.ru)
 * @version $Id$
 * @since 24.04.2017
 */
public class Pawn extends Figure {

    /**
     * constructor of thi figure.
     *
     * @param position is the position of this figure on the board
     * @param fraction is the fraction
     */
    public Pawn(Cell position, Fraction fraction) {
        super(position, fraction);
    }

    /**
     * method describes a move of this figure from position to destination.
     *
     * @param destination is cell as destination on the board.
     * @return array of cell as way of this figure from position to destination
     * @throws ImpossibleMoveException if this figure can not move from position to destination
     */
    @Override
    Cell[] way(Cell destination) throws ImpossibleMoveException {

        if ((position.getY() != destination.getY())
            || (fraction == Fraction.black && position.getX() > destination.getX())
            || (fraction == Fraction.white && position.getX() < destination.getX())
            || (Math.abs(position.getX() - destination.getX()) > 1 && position.getX() != 1 && fraction == Fraction.black)
            || (Math.abs(position.getX() - destination.getX()) > 1 && position.getX() != 6 && fraction == Fraction.white)
            || (Math.abs(position.getX() - destination.getX()) > 2 && position.getX() == 6 && fraction == Fraction.white)
            || (Math.abs(position.getX() - destination.getX()) > 2 && position.getX() == 1 && fraction == Fraction.black)) {

            throw new ImpossibleMoveException();

        }

        Cell[] result;

        if (position.getX() == 1 && destination.getX() == 3 && fraction == Fraction.black
         || position.getX() == 6 && destination.getX() == 4 && fraction == Fraction.white) {

            result = new Cell[2];
            result[0] = new Cell(rule(position.getX(), destination.getX()), position.getY());
            result[1] = destination;

        } else {

            result = new Cell[1];

            result[0] = destination;

        }

        return result;

    }

    /**
     * method clone figure and return new figure.
     *
     * @param destination is cell as position of new figure
     * @return clone figure
     */
    @Override
    public Figure clone(Cell destination) {
        return new Pawn(destination, this.fraction);
    }

}
@@ -959,24 +959,29 @@
    if ((
-p
+getP
 osition
+()
 .getY() 
@@ -1015,32 +1015,37 @@
         %7C%7C (
-f
+getF
 raction
+()
  == Fraction
@@ -1050,32 +1050,37 @@
 on.black && 
-p
+getP
 osition
+()
 .getX() %3E de
@@ -1113,24 +1113,29 @@
     %7C%7C (
-f
+getF
 raction
+()
  == Frac
@@ -1144,32 +1144,37 @@
 on.white && 
-p
+getP
 osition
+()
 .getX() %3C de
@@ -1212,32 +1212,37 @@
 %7C (Math.abs(
-p
+getP
 osition
+()
 .getX() - de
@@ -1262,32 +1262,37 @@
 X()) %3E 1 && 
-p
+getP
 osition
+()
 .getX() != 1
@@ -1291,32 +1291,37 @@
 X() != 1 && 
-f
+getF
 raction
+()
  == Fraction
@@ -1349,32 +1349,37 @@
 %7C (Math.abs(
-p
+getP
 osition
+()
 .getX() - de
@@ -1399,32 +1399,37 @@
 X()) %3E 1 && 
-p
+getP
 osition
+()
 .getX() != 6
@@ -1428,32 +1428,37 @@
 X() != 6 && 
-f
+getF
 raction
+()
  == Fraction
@@ -1486,32 +1486,37 @@
 %7C (Math.abs(
-p
+getP
 osition
+()
 .getX() - de
@@ -1536,32 +1536,37 @@
 X()) %3E 2 && 
-p
+getP
 osition
+()
 .getX() == 6
@@ -1565,32 +1565,37 @@
 X() == 6 && 
-f
+getF
 raction
+()
  == Fraction
@@ -1627,24 +1627,29 @@
 ath.abs(
-p
+getP
 osition
+()
 .getX() 
@@ -1677,24 +1677,29 @@
  %3E 2 && 
-p
+getP
 osition
+()
 .getX() 
@@ -1702,32 +1702,37 @@
 X() == 1 && 
-f
+getF
 raction
+()
  == Fraction
@@ -1840,24 +1840,29 @@
     if (
-p
+getP
 osition
+()
 .getX() 
@@ -1892,32 +1892,37 @@
 X() == 3 && 
-f
+getF
 raction
+()
  == Fraction
@@ -1940,24 +1940,29 @@
      %7C%7C 
-p
+getP
 osition
+()
 .getX() 
@@ -1996,24 +1996,29 @@
 == 4 && 
-f
+getF
 raction
+()
  == Frac
@@ -2104,24 +2104,29 @@
 ll(rule(
-p
+getP
 osition
+()
 .getX(),
@@ -2147,24 +2147,29 @@
 etX()), 
-p
+getP
 osition
+()
 .getY())
@@ -2602,24 +2602,29 @@
 n, this.
-f
+getF
 raction
+()
 );%0A    %7D

Refactor Pawn.java