JD
4 years ago
4 changed files with 81 additions and 63 deletions
-
20fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
-
30fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java
-
51fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java
-
43fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.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); |
|||
} |
|||
} |
@ -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])); |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue