Browse Source

figure movement test: white rook valid up

feat-figureMovement
JD 4 years ago
parent
commit
f38a7d5e2f
  1. 7
      fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java
  2. 7
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
  3. 8
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

7
fh.fd.ci.client/src/main/java/de/fd/fh/Figure.java

@ -16,18 +16,13 @@ public class Figure
return false; return false;
} }
int stepSize = src / fieldLength - dst / fieldLength;
int stepSize = src / fieldLength - dst / fieldLength; // hoch/runter
if (stepSize <= 0) // weißer Bauer kein Schritt "runter" if (stepSize <= 0) // weißer Bauer kein Schritt "runter"
{ {
return false; return false;
} }
if (stepSize > 1) // weißer Bauer nicht mehr als 1 Schritt nach "oben"
{
return false;
}
return true; return true;
} }
} }

7
fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java

@ -5,6 +5,13 @@ public class FigureFarmer extends Figure
@Override @Override
public boolean moveAllowed(int src, int dst, int[] field) public boolean moveAllowed(int src, int dst, int[] field)
{ {
int stepSize = src / fieldLength - dst / fieldLength; // hoch/runter
if (stepSize > 1) // weißer Bauer nicht mehr als 1 Schritt nach "oben"
{
return false;
}
return super.moveAllowed(src, dst, field); return super.moveAllowed(src, dst, field);
} }
} }

8
fh.fd.ci.client/src/test/java/de/fd/fh/FigureTest.java

@ -69,4 +69,12 @@ class FigureTest
Figure f = new FigureFarmer(); Figure f = new FigureFarmer();
assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 4, new int[Figure.fieldLength * Figure.fieldLength])); assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, Figure.fieldLength * 5 + 4, 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]));
}
} }
Loading…
Cancel
Save