TetrisGlass implements Glass { public boolean accept(Figure figure, int x, int y) { if (isOutside(figure, x, y)) { return false; } long[] alignedRows = alignFigureRowCoordinatesWithGlass(figure, x, true); boolean isOccupied = false; for (int i = 0; i < alignedRows.length; i++) { long alignedRow = alignedRows[i]; int rowPosition = y - i + figure.getTop(); if (rowPosition >= height) { continue; } isOccupied |= (occupied[rowPosition] & alignedRow) > 0; } return !isOccupied; } TetrisGlass(int width, int height, GlassEventListener... glassEventListeners); boolean accept(Figure figure, int x, int y); void drop(Figure figure, int x, int y); void empty(); @Override void figureAt(Figure figure, int x, int y); @Override List<Plot> getDroppedPlots(); @Override List<Plot> getCurrentFigurePlots(); boolean isEmpty(); static final int BITS_PER_POINT; }
@Test public void shouldAcceptWhenEmpty() { assertTrue(glass.accept(new TetrisFigure(), 1, 1)); }
@Test public void shouldRejectWhenFigurePartlyOutsideFromLeft() { assertFalse(glass.accept(new TetrisFigure(1, 0, "##"), 0, HEIGHT)); }
@Test public void shouldRejectWhenFigurePartlyOutsideFromRight() { assertFalse(glass.accept(new TetrisFigure(0, 0, "##"), WIDTH, HEIGHT)); }
@Test public void shouldRejectWhenFigurePartlyOutsideBottom() { assertFalse(glass.accept(new TetrisFigure(0, 0, "#", "#"), WIDTH, 0)); }
@Test public void shouldRejectWhenPartiallyOutsideOnRight() { assertFalse(glass.accept(new TetrisFigure(0, 0, "##"), WIDTH - 1, 0)); }