Browse Source

removed magic numbers

feat-figureMovement
JD 4 years ago
parent
commit
d8918c6790
  1. 16
      fh.fd.ci.client/src/main/java/de/fd/fh/Game.java
  2. 12
      fh.fd.ci.client/src/test/java/de/fd/fh/GameTest.java

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

@ -4,18 +4,26 @@ public class Game
{ {
public Figure[] mField; 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() public void initNewGame()
{ {
mField = new Figure[Figure.fieldLength * Figure.fieldLength]; mField = new Figure[Figure.fieldLength * Figure.fieldLength];
// Figuren platzieren // 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();
} }
} }
} }

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

@ -23,16 +23,18 @@ class GameTest
Game g = new Game(); Game g = new Game();
g.initNewGame(); 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);
} }
} }
Loading…
Cancel
Save