@Override public synchronized void startGame() { try { stopPlayer1GameTimer(); stopPlayer2GameTimer(); networkManager.sendCommand(StartGameCommand.class); player1ScoreCounter.reset(); player2ScoreCounter.reset(); updatePlayer1ScoreViewer(0); updatePlayer2ScoreViewer(0); board.getTetrisModel().clear(); board.getTetrisModel().getFigureManager1().pregenerateFigure(); board.getPlayer1PreviewerModel().clear(); board .getTetrisModel() .getFigureManager1() .getNextFigure() .putFigure(board.getPlayer1PreviewerModel(), 4, 0); final AbstractFigure figure1 = board.getTetrisModel().getFigureManager1().getCurrentFigure(); board.getTetrisModel().setFigure1(figure1); figure1.putFigure(board.getTetrisModel(), 4, 0); board.getTetrisModel().getFigureManager2().pregenerateFigure(); board.getPlayer2PreviewerModel().clear(); board .getTetrisModel() .getFigureManager2() .getNextFigure() .putFigure(board.getPlayer2PreviewerModel(), 4, 0); final AbstractFigure figure2 = board.getTetrisModel().getFigureManager2().getCurrentFigure(); board.getTetrisModel().setFigure2(figure2); figure2.putFigure(board.getTetrisModel(), 14, 0); gameStarted = true; gamePaused = false; restartPlayer1GameTimer(); restartPlayer2GameTimer(); repaintPlayer1Previewer(); repaintPlayer2Previewer(); repaintDownShifter(); } catch (IOException ex) { interraptGame(ex); } }
@Override public synchronized void player1PushDown() { if (gamePaused || !gameStarted) { return; } try { restartPlayer1GameTimer(); if (board.getTetrisModel().getFigure1().pushDown() == AbstractFigure.RESULT_FREEZED) { updatePlayer1ScoreViewer(board.getTetrisModel().removeRows()); board.getTetrisModel().getFigureManager1().pregenerateFigure(); /* * Put preview figure */ board.getPlayer1PreviewerModel().clear(); board .getTetrisModel() .getFigureManager1() .getNextFigure() .putFigure(board.getPlayer1PreviewerModel(), 4, 0); repaintPlayer1Previewer(); /* * Put new figure */ final AbstractFigure figure = board.getTetrisModel().getFigureManager1().getCurrentFigure(); board.getTetrisModel().setFigure1(figure); if (!figure.putFigure(board.getTetrisModel(), 4, 0)) { gameOver(); } else { board.getDownShifter().doShift(); networkManager.sendCommand(DoShiftCommand.class); } } updatePlayer1ScoreViewer(1); repaintDownShifter(); } catch (IOException ex) { interraptGame(ex); } }