From 00b04d6bcae1ce3a63579bd89ad5803ef135d949 Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Sun, 31 Jan 2021 12:30:11 +0100 Subject: [PATCH] added different FigurFarmer colors --- .../src/main/java/de/fd/fh/FigureFarmer.java | 35 +++++++++++++++++++ .../src/main/java/de/fd/fh/Game.java | 13 +++---- .../test/java/de/fd/fh/FigureFarmerTest.java | 10 +++--- .../src/test/java/de/fd/fh/GameTest.java | 8 +++-- 4 files changed, 53 insertions(+), 13 deletions(-) diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java b/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java index 49ec0be..8439753 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/FigureFarmer.java +++ b/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 int mColor; + + public FigureFarmer(int colorCode) + { + mColor = colorCode; + } + @Override public boolean moveAllowed(int src, int dst, Figure[] field) { @@ -23,4 +30,32 @@ public class FigureFarmer extends Figure 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; + } } diff --git a/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java b/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java index 6d5cf4b..6219439 100644 --- a/fh.fd.ci.client/src/main/java/de/fd/fh/Game.java +++ b/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); } } } diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java index 9e17ae4..bfac82e 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/FigureFarmerTest.java @@ -10,7 +10,7 @@ class FigureFarmerTest @Test void whiteFarmerValidDestination() { - Figure f = new FigureFarmer(); + Figure f = new FigureFarmer(0); assertTrue(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 5 + 0, new Figure[Figure.fieldLength * Figure.fieldLength])); @@ -19,7 +19,7 @@ class FigureFarmerTest @Test 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, Figure.fieldLength * 7 + 0, new Figure[Figure.fieldLength * Figure.fieldLength])); @@ -28,7 +28,7 @@ class FigureFarmerTest @Test void whiteFarmerInvalidDestinationUp() // mehr als 1 Schritt nach "oben" { - Figure f = new FigureFarmer(); + Figure f = new FigureFarmer(0); assertFalse(f.moveAllowed(Figure.fieldLength * 6 + 0, Figure.fieldLength * 4 + 0, new Figure[Figure.fieldLength * Figure.fieldLength])); @@ -37,7 +37,7 @@ class FigureFarmerTest @Test 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, Figure.fieldLength * 3 + 4, new Figure[Figure.fieldLength * Figure.fieldLength])); @@ -46,7 +46,7 @@ class FigureFarmerTest @Test 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, Figure.fieldLength * 5 + 4, new Figure[Figure.fieldLength * Figure.fieldLength])); diff --git a/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java b/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java index 858efc2..b260a15 100644 --- a/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java +++ b/fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java @@ -51,15 +51,19 @@ class GameTest // weiße Bauern 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()); + assertEquals(new FigureFarmer(0), + g.mField[Game.whiteRowFarmer * Figure.fieldLength + j]); } // schwarze Bauern 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()); + assertEquals(new FigureFarmer(1), + g.mField[Game.blackRowFarmer * Figure.fieldLength + j]); } } } \ No newline at end of file