public synchronized void player2TurnCounterClockwise() { if (!board.getTetrisModel().getFigure2().turnCounterClockwise()) { blink(); } repaintDownShifter(); }
@Override public synchronized void player1TurnClockwise() { if (!board.getTetrisModel().getFigure1().turnClockwise()) { blink(); } repaintDownShifter(); }
public void gameOver() { try { stopPlayer1GameTimer(); stopPlayer2GameTimer(); networkManager.sendCommand(GameOverCommand.class); gameStarted = false; board.getTetrisModel().setMessage("Game over"); } catch (IOException e) { interraptGame(e); } }
@Override public synchronized void resumeGame() { if (gameStarted && gamePaused) { try { restartPlayer1GameTimer(); restartPlayer2GameTimer(); networkManager.sendCommand(ResumeGameCommand.class); gamePaused = false; board.getTetrisModel().setMessage(null); repaintDownShifter(); } catch (IOException ex) { interraptGame(ex); } } }
@Override public synchronized void pauseGame() { if (gameStarted && !gamePaused) { try { stopPlayer1GameTimer(); stopPlayer2GameTimer(); networkManager.sendCommand(PauseGameCommand.class); gamePaused = true; board.getTetrisModel().setMessage("pause"); 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); } }
@Override public synchronized void player1PushRight() { if (board.getTetrisModel().getFigure1().pushRight()) { repaintDownShifter(); } }
public synchronized void player2PushLeft() { if (board.getTetrisModel().getFigure2().pushLeft()) { repaintDownShifter(); } }
@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); } }