From 6bb0b903aa12687bc1e95007795e64cae5389071 Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Fri, 15 Jan 2021 18:17:36 +0100 Subject: [PATCH] refactored rowDiff / relStep --- .../src/main/java/de/fd/fh/FigureRook.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java index 02b622b..968180f 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java +++ b/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; }