TetrisGame implements Joystick, Game { public void tick() { if (theFirstStep()) { takeFigure(); return; } if (!glass.accept(currentFigure, x, y)) { glass.empty(); currentFigure = null; tick(); return; } if (dropRequested) { dropRequested = false; glass.drop(currentFigure, x, y); currentFigure = null; tick(); return; } if (!glass.accept(currentFigure, x, y - 1)) { glass.drop(currentFigure, x, y); currentFigure = null; tick(); return; } y--; showCurrentFigure(); } TetrisGame(FigureQueue queue, final Glass glass, PrinterFactory factory); void tick(); void down(); @Override void up(); @Override void left(); @Override void right(); @Override void act(int... p); void act(int times); Figure.Type getCurrentFigureType(); int getCurrentFigureX(); int getCurrentFigureY(); List<Figure.Type> getFutureFigures(); @Override Joystick getJoystick(); @Override int getMaxScore(); @Override int getCurrentScore(); @Override boolean isGameOver(); @Override void newGame(); @Override String getBoardAsString(); @Override void destroy(); @Override void clearScore(); @Override Point getHero(); @Override String getSave(); static final int GLASS_HEIGHT; static final int GLASS_WIDTH; }
@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 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()); }
@Test @GivenFiguresInQueue({@FigureProperties, @FigureProperties(left = 1)}) public void shouldOverflowWhenFigureRejectedAtFirstStep(){ rejectWhenCoordinates(CENTER_X, HEIGHT); 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); }