Browse Source

refactored color type

feat-figureMovement
JD 4 years ago
parent
commit
de43590ca1
  1. 5
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
  2. 4
      fh.fd.ci.client/src/main/java/de/fd/fh/Game.java
  3. 10
      fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java
  4. 8
      fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java

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

@ -2,9 +2,10 @@ package de.fd.fh;
public class FigureFarmer extends Figure public class FigureFarmer extends Figure
{ {
public int mColor;
enum Color { Black, White};
public Color mColor;
public FigureFarmer(int colorCode)
public FigureFarmer(Color colorCode)
{ {
mColor = colorCode; mColor = colorCode;
} }

4
fh.fd.ci.client/src/main/java/de/fd/fh/Game.java

@ -27,12 +27,12 @@ public class Game
for (int j = 0; j < Figure.fieldLength; j++) // col for (int j = 0; j < Figure.fieldLength; j++) // col
{ {
mField[Game.whiteRowFarmer * Figure.fieldLength + j] = new FigureFarmer(0);
mField[Game.whiteRowFarmer * Figure.fieldLength + j] = new FigureFarmer(FigureFarmer.Color.White);
} }
for (int j = 0; j < Figure.fieldLength; j++) // col for (int j = 0; j < Figure.fieldLength; j++) // col
{ {
mField[Game.blackRowFarmer * Figure.fieldLength + j] = new FigureFarmer(1);
mField[Game.blackRowFarmer * Figure.fieldLength + j] = new FigureFarmer(FigureFarmer.Color.Black);
} }
} }
} }

10
fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java

@ -10,7 +10,7 @@ class FigureFarmerTest
@Test @Test
void whiteFarmerValidDestination() void whiteFarmerValidDestination()
{ {
Figure f = new FigureFarmer(0);
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0,
Figure.fieldLength * 5 + 0, Figure.fieldLength * 5 + 0,
new Figure[Figure.fieldLength * Figure.fieldLength])); new Figure[Figure.fieldLength * Figure.fieldLength]));
@ -19,7 +19,7 @@ class FigureFarmerTest
@Test @Test
void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen void whiteFarmerInvalidDestinationDown() // statt nach "oben" wird nach "unten" gegangen
{ {
Figure f = new FigureFarmer(0);
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0,
Figure.fieldLength * 7 + 0, Figure.fieldLength * 7 + 0,
new Figure[Figure.fieldLength * Figure.fieldLength])); new Figure[Figure.fieldLength * Figure.fieldLength]));
@ -28,7 +28,7 @@ class FigureFarmerTest
@Test @Test
void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben" void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben"
{ {
Figure f = new FigureFarmer(0);
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0,
Figure.fieldLength * 4 + 0, Figure.fieldLength * 4 + 0,
new Figure[Figure.fieldLength * Figure.fieldLength])); new Figure[Figure.fieldLength * Figure.fieldLength]));
@ -37,7 +37,7 @@ class FigureFarmerTest
@Test @Test
void checkMoveWithValidDestinationVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach oben void checkMoveWithValidDestinationVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach oben
{ {
Figure f = new FigureFarmer(0);
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4, assertTrue(f.moveAllowed(Figure.fieldLength * 4 + 4,
Figure.fieldLength * 3 + 4, Figure.fieldLength * 3 + 4,
new Figure[Figure.fieldLength * Figure.fieldLength])); new Figure[Figure.fieldLength * Figure.fieldLength]));
@ -46,7 +46,7 @@ class FigureFarmerTest
@Test @Test
void whiteFarmerInvalidDestinationDownVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach unten void whiteFarmerInvalidDestinationDownVar2() // Bauer (w) steht in der Mitte vom Feld und geht 1 nach unten
{ {
Figure f = new FigureFarmer(0);
Figure f = new FigureFarmer(FigureFarmer.Color.White);
assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4, assertFalse(f.moveAllowed(Figure.fieldLength * 4 + 4,
Figure.fieldLength * 5 + 4, Figure.fieldLength * 5 + 4,
new Figure[Figure.fieldLength * Figure.fieldLength])); new Figure[Figure.fieldLength * Figure.fieldLength]));

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

@ -51,18 +51,18 @@ class GameTest
// weiße Bauern // weiße Bauern
for (int j = 0; j < Figure.fieldLength; j++) // col for (int j = 0; j < Figure.fieldLength; j++) // col
{ {
assertEquals(new FigureFarmer(0).getClass(),
assertEquals(new FigureFarmer(FigureFarmer.Color.White).getClass(),
g.mField[Game.whiteRowFarmer * Figure.fieldLength + j].getClass()); g.mField[Game.whiteRowFarmer * Figure.fieldLength + j].getClass());
assertEquals(new FigureFarmer(0),
assertEquals(new FigureFarmer(FigureFarmer.Color.White),
g.mField[Game.whiteRowFarmer * Figure.fieldLength + j]); g.mField[Game.whiteRowFarmer * Figure.fieldLength + j]);
} }
// schwarze Bauern // schwarze Bauern
for (int j = 0; j < Figure.fieldLength; j++) // col for (int j = 0; j < Figure.fieldLength; j++) // col
{ {
assertEquals(new FigureFarmer(1).getClass(),
assertEquals(new FigureFarmer(FigureFarmer.Color.Black).getClass(),
g.mField[Game.blackRowFarmer * Figure.fieldLength + j].getClass()); g.mField[Game.blackRowFarmer * Figure.fieldLength + j].getClass());
assertEquals(new FigureFarmer(1),
assertEquals(new FigureFarmer(FigureFarmer.Color.Black),
g.mField[Game.blackRowFarmer * Figure.fieldLength + j]); g.mField[Game.blackRowFarmer * Figure.fieldLength + j]);
} }
} }
Loading…
Cancel
Save