Пример #1
0
  /** sets the amoebes to random squares, two for each player */
  private void setAmoebesToSquares() {
    Die die = dieProvider.get();
    for (int i = 0; i < this.players.length; i++) {
      Game.Color color = this.players[i].getColor();
      boolean statusOK =
          false; // AK this sounds a bit over-dramatic, "freeSquare" seems more appropriate
      int randomRow, randomCol;
      do {
        randomRow =
            die.roll(1, 5)
                - 1; // AK could you maybe implement a `choose(List<Square> from) : Square` function
                     // that
        randomCol =
            die.roll(1, 5)
                - 1; // guarantees that even if I'm unlucky (or have badly mocked), always halts?
        statusOK = Board.board[randomRow][randomCol].getAmoebesList().size() == 0;
      } while (!statusOK);
      Amoebe amo1 = AmoebeFactory.get(this.compassProvider, color);
      board[randomRow][randomCol].enterSquare(amo1);

      statusOK =
          false; // AK don't repeat yourselves, you could have done the same with a simple for-loop
                 // here.
      do { // remember that more code is more place for error
        randomRow = die.roll(1, 5) - 1;
        randomCol = die.roll(1, 5) - 1;
        statusOK = Board.board[randomRow][randomCol].getAmoebesList().size() == 0;
      } while (!statusOK);
      Amoebe amo2 = AmoebeFactory.get(this.compassProvider, color);
      board[randomRow][randomCol].enterSquare(amo2);
    }
  }
Пример #2
0
 @Test
 public void amoebeShouldHaveCorrectDamagePoints() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   assertTrue(amoebe.getDamagePoints() == 0);
   amoebe.addDamagePoint();
   assertTrue(amoebe.getDamagePoints() == 1);
 }
Пример #3
0
 @Test
 public void amoebeShouldBeSetToASquare() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   assertTrue(amoebe.getSquare().getPosition()[0] == 0);
   assertTrue(amoebe.getSquare().getPosition()[1] == 0);
 }
Пример #4
0
 @Test
 public void amoebeShouldExcrement() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   square.enterSquare(amoebe);
   assertTrue(square.getFoodcubes().size() == 6);
   amoebe.excrement();
   assertTrue(square.getFoodcubes().size() == 8);
 }
Пример #5
0
 @Test
 public void amoebeShouldDie() {
   Amoebe amoebe = AmoebeFactory.get(this.compassProvider, Game.Color.RED);
   int[] position = {0, 0};
   Square square = SquareFactory.get(position);
   amoebe.setSquare(square);
   square.enterSquare(amoebe);
   assertTrue(square.getAmoebesList().size() == 1);
   amoebe.die();
   assertTrue(square.getAmoebesList().size() == 0);
 }
Пример #6
0
 /** divide the amoebe */
 public Amoebe divide() {
   return AmoebeFactory.get(this.compassProvider, this.color);
 }