@Test
  @GivenFiguresInQueue({@FigureProperties})
  public void shouldBeMovedRightWhenAsked() {
    game.right();
    game.tick();

    assertCoordinates(CENTER_X + 1, TOP_Y - 1);
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties(bottom = 1), @FigureProperties(bottom = 2)})
  public void shouldTakeNextFigureWhenCurrentIsDropped() {
    game.down();
    game.tick();

    assertCoordinates(CENTER_X, HEIGHT);
    assertEquals(2, figureCaptor.getValue().getBottom());
  }
  @Test
  public void shouldRotateOnce() {
    TetrisGame game = createGameWithOneFigureInQueue(letterIFigure);
    glassToAcceptFigure();
    game.tick();

    game.act(1);

    captureFigureAtValues();
    Figure capturedFigure = figureCaptor.getValue();
    assertThat(capturedFigure.getRowCodes(false)).isEqualTo(new int[] {0b001001001001});
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties})
  public void shouldChangePositionWhenOnlyNextStep() {
    game.left();

    assertCoordinates(CENTER_X, TOP_Y);
  }
Beispiel #5
0
  void clearCompletedCells() {
    super.clearCompletedCells();

    int clearedCells = 0;
    SortedSet<Block> cells =
        new TreeSet<Block>(
            new Comparator<Block>() {
              public int compare(Block a, Block b) {
                //	order by left to right, top to bottom
                if (a.getY() < b.getY()) return -1;
                if (a.getY() > b.getY()) return 1;
                if (a.getX() < b.getX()) return -1;
                if (a.getX() > b.getX()) return 1;
                // both X and Y equals
                return 0;
              }
            });

    //	Check all cells that need to be cleared.
    for (int y = 0; y < getRows(); y++) {
      for (int x = 0; x < getColumns(); x++) {
        getAllMatchedCells(cells, x, y);
      }
    }

    //	for all matched cells, move cell on top of them down
    for (Block block : cells) {
      moveCelledAboveClearedCell(block.getX(), block.getY());
    }
    // score += cells.size()*5;
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties(right = 1)})
  public void shouldIncludeFigureSizeWhenMoveRight() {
    right(CENTER_X + 1);
    game.tick();

    assertCoordinates(9 - 1, HEIGHT - 1);
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties})
  public void shouldNotMoveOutWhenRightSide() {
    right(CENTER_X + 2);
    game.tick();

    assertCoordinates(9, TOP_Y - 1);
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties})
  public void shouldNotChangeCurrentFigureWhenNextStep() {
    game.tick();

    captureFigureAtValues();
    List<Figure> allFigures = figureCaptor.getAllValues();
    assertSame(allFigures.get(0), allFigures.get(1));
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties(bottom = HEIGHT), @FigureProperties(bottom = 1)})
  public void shouldGameOverWhenGlassOverflown() {
    glassToRejectFigure();
    game.tick();

    assertCoordinates(CENTER_X, HEIGHT);
    assertGameOver();
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties, @FigureProperties(left = 1)})
  public void shouldPerformDropWhenRejected() {
    acceptWhenCoordinates(CENTER_X, HEIGHT);
    rejectWhenCoordinates(CENTER_X, HEIGHT - 1);

    game.tick();

    verifyDroppedAt(CENTER_X, HEIGHT);
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties, @FigureProperties(left = 1)})
  public void shouldOverflowWhenFigureRejectedAtFirstStep() {
    rejectWhenCoordinates(CENTER_X, HEIGHT);

    game.tick();

    assertCoordinates(CENTER_X, HEIGHT);
    assertGameOver();
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties})
  public void shouldMoveRightWhenAcceptOnly() {
    rejectWhenCoordinates(CENTER_X + 1, HEIGHT);
    acceptWhenCoordinates(CENTER_X, HEIGHT - 1);

    right(1);
    game.tick();

    assertCoordinates(CENTER_X, HEIGHT - 1);
  }
  @Test
  @GivenFiguresInQueue({@FigureProperties, @FigureProperties(left = 1)})
  public void shouldTakeNextFigureWhenRejectedAfterNextStep() {
    acceptWhenCoordinates(CENTER_X, HEIGHT);
    rejectWhenCoordinates(CENTER_X, HEIGHT - 1);

    game.tick();

    captureFigureAtValues();
    assertThat(yCaptor.getAllValues()).isEqualTo(Arrays.asList(HEIGHT, HEIGHT));
    assertEquals(1, figureCaptor.getValue().getLeft());
  }
 private void right(int times) {
   for (int i = 0; i < times; i++) {
     game.right();
   }
 }
 private void left(int times) {
   for (int i = 0; i < times; i++) {
     game.left();
   }
 }