Beispiel #1
0
  @Test
  public void shouldSaveCommandAndActAfterTick() {
    shouldBoardWith(new Sapper(2, 2), new Mine(3, 2));

    board.getJoystick().right();

    assertBoard("☼☼☼☼☼\n" + "☼***☼\n" + "☼*☺*☼\n" + "☼***☼\n" + "☼☼☼☼☼\n");

    board.tick();

    assertBoard("☼☼☼☼☼\n" + "☼ 11☼\n" + "☼ 1Ѡ☼\n" + "☼ 11☼\n" + "☼☼☼☼☼\n");

    assertTrue(board.isGameOver());
  }
Beispiel #2
0
  @Test
  public void shouldDie_whenSapperAtBombs() {
    shouldBoardWith(new Sapper(2, 2), new Mine(3, 2));

    moveRight();

    assertBoard("☼☼☼☼☼\n" + "☼ 11☼\n" + "☼ 1Ѡ☼\n" + "☼ 11☼\n" + "☼☼☼☼☼\n");

    assertTrue(board.isGameOver());
  }
Beispiel #3
0
  @Test
  public void shouldPrintAllBombs_whenSapperAtBombs() {
    shouldBoardWith(
        new Sapper(2, 2),
        new Mine(3, 3),
        new Mine(3, 2),
        new Mine(3, 1),
        new Mine(2, 1),
        new Mine(2, 3));

    unbombUp();
    unbombDown();
    unbombLeft();
    moveRight();

    assertBoard("☼☼☼☼☼\n" + "☼ x☻☼\n" + "☼‼3Ѡ☼\n" + "☼ x☻☼\n" + "☼☼☼☼☼\n");

    assertTrue(board.isGameOver());
  }
Beispiel #4
0
 private void moveRight() {
   board.getJoystick().right();
   board.tick();
 }
Beispiel #5
0
 private void moveDown() {
   board.getJoystick().down();
   board.tick();
 }
Beispiel #6
0
 private void shouldBoardWith(Sapper sapper, Mine... mines) {
   listener = mock(EventListener.class);
   board = new MockBoard(sapper, mines);
   board.newGame();
 }
Beispiel #7
0
 private void assertBoard(String expected) {
   assertEquals(expected, new Printer(board.getSize(), new MinesweeperPrinter(board)).toString());
 }
Beispiel #8
0
 private void unbombLeft() {
   board.getJoystick().act();
   moveLeft();
 }
Beispiel #9
0
 private void unbombDown() {
   board.getJoystick().act();
   moveDown();
 }
Beispiel #10
0
 private void unbombRight() {
   board.getJoystick().act();
   moveRight();
 }
Beispiel #11
0
 private void moveLeft() {
   board.getJoystick().left();
   board.tick();
 }
Beispiel #12
0
 private void unbombUp() {
   board.getJoystick().act();
   moveUp();
 }
Beispiel #13
0
 private void assertStillNotWin() {
   assertFalse(board.isWin());
 }
Beispiel #14
0
 private void moveUp() {
   board.getJoystick().up();
   board.tick();
 }
Beispiel #15
0
 private void assertWin() {
   assertTrue(board.isWin());
 }