diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java index f2c6a43..d592c94 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java @@ -16,26 +16,6 @@ public class Figure return false; } - if (src / fieldLength - dst / fieldLength > 0 && src % fieldLength - dst % fieldLength > 0) // diagonal nach links oben - { - return false; - } - - if (src / fieldLength - dst / fieldLength > 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts oben - { - return false; - } - - if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength > 0) // diagonal nach rechts oben - { - return false; - } - - if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts unten - { - return false; - } - return true; } } 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 new file mode 100644 index 0000000..02b622b --- /dev/null +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java @@ -0,0 +1,30 @@ +package de.fd.fh; + +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 + { + return false; + } + + if (src / fieldLength - dst / fieldLength > 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts oben + { + return false; + } + + if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength > 0) // diagonal nach rechts oben + { + return false; + } + + if (src / fieldLength - dst / fieldLength < 0 && src % fieldLength - dst % fieldLength < 0) // diagonal nach rechts unten + { + return false; + } + + return super.moveAllowed(src, dst, field); + } +} diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java new file mode 100644 index 0000000..b2f73f1 --- /dev/null +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java @@ -0,0 +1,51 @@ +package de.fd.fh; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FigureRookTest +{ + // weißer Turm + @Test + void whiteRookValidMoveUp() + { + Figure f = new FigureRook(); + assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 0 + 4, new int[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookValidMoveDown() + { + Figure f = new FigureRook(); + assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 7 + 4, new int[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveLeftUp() // diagonal nach links oben + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 3 + 3, new int[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveRightUp() // diagonal nach rechts oben + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 3 + 5, new int[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveLeftDown() // diagonal nach links unten + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 3, new int[Figure.fieldLength * Figure.fieldLength])); + } + + @Test + void whiteRookInvalidMoveRightDown() // diagonal nach rechts unten + { + Figure f = new FigureRook(); + assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 5, new int[Figure.fieldLength * Figure.fieldLength])); + } +} \ No newline at end of file diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java index c3dcc90..60271c1 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java @@ -33,47 +33,4 @@ class FigureTest Figure f = new Figure(); assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 6 + 0, new int[Figure.fieldLength * Figure.fieldLength])); } - - // weißer Turm - @Test - void whiteRookValidMoveUp() - { - Figure f = new Figure(); - assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 0 + 4, new int[Figure.fieldLength * Figure.fieldLength])); - } - - @Test - void whiteRookValidMoveDown() - { - Figure f = new Figure(); - assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 7 + 4, new int[Figure.fieldLength * Figure.fieldLength])); - } - - @Test - void whiteRookInvalidMoveLeftUp() // diagonal nach links oben - { - Figure f = new Figure(); - assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 3 + 3, new int[Figure.fieldLength * Figure.fieldLength])); - } - - @Test - void whiteRookInvalidMoveRightUp() // diagonal nach rechts oben - { - Figure f = new Figure(); - assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 3 + 5, new int[Figure.fieldLength * Figure.fieldLength])); - } - - @Test - void whiteRookInvalidMoveLeftDown() // diagonal nach links unten - { - Figure f = new Figure(); - assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 3, new int[Figure.fieldLength * Figure.fieldLength])); - } - - @Test - void whiteRookInvalidMoveRightDown() // diagonal nach rechts unten - { - Figure f = new Figure(); - assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 5, new int[Figure.fieldLength * Figure.fieldLength])); - } } \ No newline at end of file