private void updatePlayer2ScoreViewer(int removedRowNumber) { player2ScoreCounter.increaseScores(removedRowNumber); board .getPlayer2ScoresViewer() .update( player2ScoreCounter.getScores(), player2ScoreCounter.getNextLevelScores(), player2ScoreCounter.getLevel()); }
@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); } }
private void restartPlayer2GameTimer() { stopPlayer2GameTimer(); player2GameTimer = new Timer(true); player2GameTimer.schedule( new TimerTask() { @Override public void run() { synchronized (GameControllerServer.this) { if (gamePaused || !gameStarted) { return; } try { 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); } } repaintDownShifter(); } catch (IOException e) { interraptGame(e); } } } }, player2ScoreCounter.getSpeed(), player2ScoreCounter.getSpeed()); }