diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java new file mode 100644 index 0000000..4c2c230 --- /dev/null +++ b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureKing.java @@ -0,0 +1,25 @@ +package de.fd.fh; + +public class FigureKing extends Figure +{ + @Override + public boolean moveAllowed(int src, int dst, Figure[] field) + { + // TODO: Positionierung in einer Ecke beachten + if (dst != src-1 + || dst != src +1 + + || dst != src -8 + || dst != src -8 -1 + || dst != src -8 +1 + + || dst != src +8 + || dst != src +8 -1 + || dst != src +8 +1) + { + return false; + } + + return super.moveAllowed(src, dst, field); + } +} diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java new file mode 100644 index 0000000..1f03a35 --- /dev/null +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureKingTest.java @@ -0,0 +1,28 @@ +package de.fd.fh; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class FigureKingTest +{ + // K = Position (19), x = gültig (10, 11, 12, 18, 20, 26, 27, 28), rest nicht + // x x x + // x K x + // x x x + @Test + void checkInvalidKingMoves() + { + Figure f = new FigureKing(); + + for (int i = 0; i < 64; i++) + { + if (i != 10 && i != 11 && i != 12 + && i != 18 && i != 20 + && i != 26 && i != 27 && i != 28) + { + assertFalse(f.moveAllowed(19, i, new Figure[64])); + } + } + } +} \ No newline at end of file