Browse Source

added different FigurFarmer colors

feat-figureMovement
JD 4 years ago
parent
commit
00b04d6bca
  1. 35
      fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java
  2. 9
      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

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

@ -2,6 +2,13 @@ package de.fd.fh;
public class FigureFarmer extends Figure public class FigureFarmer extends Figure
{ {
public int mColor;
public FigureFarmer(int colorCode)
{
mColor = colorCode;
}
@Override @Override
public boolean moveAllowed(int src, int dst, Figure[] field) public boolean moveAllowed(int src, int dst, Figure[] field)
{ {
@ -23,4 +30,32 @@ public class FigureFarmer extends Figure
return super.moveAllowed(src, dst, field); return super.moveAllowed(src, dst, field);
} }
@Override
public boolean equals(Object o)
{
if (o == null)
{
return false;
}
if (this == o)
{
return true;
}
if (this.getClass() != o.getClass())
{
return false;
}
FigureFarmer otherFigure = (FigureFarmer)o;
if (this.mColor != otherFigure.mColor)
{
return false;
}
return true;
}
} }

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

@ -25,13 +25,14 @@ public class Game
} }
} }
if (i == Game.whiteRowFarmer
|| i == Game.blackRowFarmer)
{
for (int j = 0; j < Figure.fieldLength; j++) // col for (int j = 0; j < Figure.fieldLength; j++) // col
{ {
mField[i * Figure.fieldLength + j] = new FigureFarmer();
mField[Game.whiteRowFarmer * Figure.fieldLength + j] = new FigureFarmer(0);
} }
for (int j = 0; j < Figure.fieldLength; j++) // col
{
mField[Game.blackRowFarmer * Figure.fieldLength + j] = new FigureFarmer(1);
} }
} }
} }

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();
Figure f = new FigureFarmer(0);
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();
Figure f = new FigureFarmer(0);
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();
Figure f = new FigureFarmer(0);
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();
Figure f = new FigureFarmer(0);
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();
Figure f = new FigureFarmer(0);
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,15 +51,19 @@ 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().getClass(),
assertEquals(new FigureFarmer(0).getClass(),
g.mField[Game.whiteRowFarmer * Figure.fieldLength + j].getClass()); g.mField[Game.whiteRowFarmer * Figure.fieldLength + j].getClass());
assertEquals(new FigureFarmer(0),
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().getClass(),
assertEquals(new FigureFarmer(1).getClass(),
g.mField[Game.blackRowFarmer * Figure.fieldLength + j].getClass()); g.mField[Game.blackRowFarmer * Figure.fieldLength + j].getClass());
assertEquals(new FigureFarmer(1),
g.mField[Game.blackRowFarmer * Figure.fieldLength + j]);
} }
} }
} }
Loading…
Cancel
Save