Browse Source

refactored rowDiff / relStep

feat-figureMovement
JD 4 years ago
parent
commit
6bb0b903aa
  1. 11
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java

11
fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java

@ -5,22 +5,25 @@ public class FigureRook extends Figure
@Override
public boolean moveAllowed(int src, int dst, int[] field)
{
if (src / fieldLength - dst / fieldLength > 0 && src % fieldLength - dst % fieldLength > 0) // diagonal nach links oben
int rowDiff = src / fieldLength - dst / fieldLength; // hoch/runter
int relStep = src % fieldLength - dst % fieldLength; // links//rechts
if (rowDiff > 0 && relStep > 0) // diagonal nach links oben
{
return false;
}
if (src / fieldLength - dst / fieldLength > 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts oben
if (rowDiff > 0 && relStep < 0) // diagonal nach rechts oben
{
return false;
}
if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength > 0) // diagonal nach rechts oben
if (rowDiff < 0 && relStep > 0) // diagonal nach rechts oben
{
return false;
}
if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts unten
if (rowDiff < 0 && relStep < 0) // diagonal nach rechts unten
{
return false;
}

Loading…
Cancel
Save