Browse Source

new class FigureRook

feat-figureMovement
JD 4 years ago
parent
commit
efedb43ce6
  1. 20
      fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
  2. 30
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureRook.java
  3. 51
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureRookTest.java
  4. 43
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

20
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;
}
}

30
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);
}
}

51
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]));
}
}

43
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]));
}
}
Loading…
Cancel
Save