Пример #1
0
  public void testThereExistsABombAtThisPositionBelongingToPlayerFunction() throws Throwable {
    Bombs bombs = new Bombs();
    Boats boats = new Boats();
    GameOverChecker gameOverChecker = new GameOverChecker(bombs, boats);

    Position placeABomb = new Position(1, 'j');
    Position nothing = new Position(5, 'f');
    Player player = Player.PLAYER1;
    Player notPlayer = Player.PLAYER2;
    bombs.placeBomb(placeABomb, player);

    assertTrue(gameOverChecker.thereExistsABombAtThisPositionFiredAtPlayer(placeABomb, player));
    assertFalse(gameOverChecker.thereExistsABombAtThisPositionFiredAtPlayer(nothing, player));
    assertFalse(gameOverChecker.thereExistsABombAtThisPositionFiredAtPlayer(placeABomb, notPlayer));
    assertFalse(gameOverChecker.thereExistsABombAtThisPositionFiredAtPlayer(nothing, notPlayer));
  }
Пример #2
0
  private GameOverChecker getGameOverGameOverCheckerWithWinner(Player player) {
    Bombs bombs = new Bombs();
    Boats boats = new Boats();
    GameOverChecker gameOverChecker = new GameOverChecker(bombs, boats);
    Position pos = new Position(1, 'j');
    Direction direction = Direction.RIGHT;
    Orientation orientation = new Orientation(pos, direction);

    for (Boat boat : boats.getBoats()) {
      boat.placeBoat(orientation);
    }

    Player toBombPlayer;
    if (player == Player.PLAYER1) toBombPlayer = Player.PLAYER2;
    else toBombPlayer = Player.PLAYER1;

    for (int i = 1; i < 10; i++) {
      pos = new Position(i, 'j');
      bombs.placeBomb(pos, toBombPlayer);
    }

    return gameOverChecker;
  }