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 569f9bb..2e99b36 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 @@ -36,4 +36,19 @@ public class Game } } } + + boolean moveFigure(int src, int dst) + { + Figure f = mField[src]; + + if (!f.moveAllowed(src, dst, mField)) + { + return false; + } + + mField[dst] = f; + mField[src] = null; + + return true; + } } 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 52664f7..241db7b 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 @@ -66,4 +66,24 @@ class GameTest g.mField[Game.blackRowFarmer * Figure.fieldLength + j]); } } + + @Test + void moveFarmerWhite() // weißer Bauer ganz links um ein Feld noch vorne bewegen + { + Game g = new Game(); + g.initNewGame(); + + // zu bewegende Figur + Figure f = g.mField[Game.whiteRowFarmer * 8 + 0]; + + // Ziel sollte leer sein + assertNull(g.mField[(Game.whiteRowFarmer - 1) * 8 + 0]); + + // Figur bewegen + assertTrue(g.moveFigure(Game.whiteRowFarmer * 8 + 0, (Game.whiteRowFarmer - 1) * 8 + 0)); + + // Figur sollte nun verschoben sein + assertNull(g.mField[Game.whiteRowFarmer * 8 + 0]); + assertSame(f, g.mField[(Game.whiteRowFarmer - 1) * 8 + 0]); + } } \ No newline at end of file