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