From d8918c6790398342bfa9ddd8b5845815e1ba6518 Mon Sep 17 00:00:00 2001 From: Julius Dewender Date: Sun, 31 Jan 2021 11:55:23 +0100 Subject: [PATCH] removed magic numbers --- fh.fd.ci.client/src/main/java/de/fd/fh/Game.java | 16 ++++++++++++---- .../src/test/java/de/fd/fh/GameTest.java | 12 +++++++----- 2 files changed, 19 insertions(+), 9 deletions(-) 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 cb0606a..f0bb2a1 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 @@ -4,18 +4,26 @@ public class Game { public Figure[] mField; + public static final int whiteRowOther = 0; + public static final int whiteRowFarmer = 1; + public static final int blackRowOther = 6; + public static final int blackRowFarmer = 7; + public void initNewGame() { mField = new Figure[Figure.fieldLength * Figure.fieldLength]; // Figuren platzieren - for (int i = 0; i < 8; i++) // row + for (int i = 0; i < Figure.fieldLength; i++) // row { - if (i == 0 || i == 1 || i == 6 || i == 7) + if (i == Game.whiteRowOther + || i == Game.whiteRowFarmer + || i == Game.blackRowOther + || i == Game.blackRowFarmer) { - for (int j = 0; j < 8; j++) // col + for (int j = 0; j < Figure.fieldLength; j++) // col { - mField[i * 8 + j] = new Figure(); + mField[i * Figure.fieldLength + j] = new Figure(); } } } 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 59fa60e..ccccad9 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 @@ -23,16 +23,18 @@ class GameTest Game g = new Game(); g.initNewGame(); - for (int i = 0; i < 8; i++) // row + for (int i = 0; i < Figure.fieldLength; i++) // row { - if (i == 0 || i == 1 || i == 6 || i == 7) + if (i == Game.whiteRowOther + || i == Game.whiteRowFarmer + || i == Game.blackRowOther + || i == Game.blackRowFarmer) { - for (int j = 0; j < 8; j++) // col + for (int j = 0; j < Figure.fieldLength; j++) // col { - assertNotEquals(null, g.mField[i * 8 + j]); + assertNotEquals(null, g.mField[i * Figure.fieldLength + j]); } } } - assertEquals(Figure.fieldLength * Figure.fieldLength, g.mField.length); } } \ No newline at end of file