@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); } }
public synchronized void player2PushDown() { if (gamePaused || !gameStarted) { return; } try { restartPlayer2GameTimer(); if (board.getTetrisModel().getFigure2().pushDown() == AbstractFigure.RESULT_FREEZED) { updatePlayer2ScoreViewer(board.getTetrisModel().removeRows()); board.getTetrisModel().getFigureManager2().pregenerateFigure(); /* * Put preview figure */ board.getPlayer2PreviewerModel().clear(); board .getTetrisModel() .getFigureManager2() .getNextFigure() .putFigure(board.getPlayer2PreviewerModel(), 4, 0); repaintPlayer2Previewer(); /* * Put new figure */ final AbstractFigure figure = board.getTetrisModel().getFigureManager2().getCurrentFigure(); board.getTetrisModel().setFigure2(figure); if (!figure.putFigure(board.getTetrisModel(), 14, 0)) { gameOver(); } else { board.getDownShifter().doShift(); networkManager.sendCommand(DoShiftCommand.class); } } updatePlayer2ScoreViewer(1); repaintDownShifter(); } catch (IOException ex) { interraptGame(ex); } }