Example #1
0
  public void update(Observable o, Object arg) {

    String gameStatus = model.getStatus();

    if (gameStatus.equals("finished")) {
      statusbar.setText("Game over. You won.");
    } else if (gameStatus.equals("paused")) {
      statusbar.setText("Paused");
    } else if (gameStatus.equals("game over")) {
      statusbar.setText("Game over. You lost.");
    } else {
      statusbar.setText(
          "Your score: "
              + new Integer(model.getScore()).toString()
              + ", level "
              + new Integer(model.getLevel()).toString());
      board.repaint();
    }
  }
Example #2
0
  /** Start the UI Rendering thread. */
  private void initUI() {
    setSize(dimension);
    add(board);

    setTitle("Game of Life");
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setLocationRelativeTo(null);

    Runnable r =
        () -> {
          while (true) {
            try {
              Thread.sleep(700);
            } catch (InterruptedException e) {
              e.printStackTrace();
            }
            board.revalidate();
            board.repaint();
          }
        };
    new Thread(r).start();
  }
Example #3
0
 private void newState(TetrisGameState state) {
   if (state.playerDisconnected) {
     JOptionPane.showMessageDialog(this, "Your opponent has disconnected.\nThe game is ended.");
     System.exit(0);
   }
   this.state = state;
   board.repaint();
   if (!state.gameInProgress || state == null) {
     return;
   } else if (state.winner != -1 || state.tie) {
     setTitle("Game Over");
   } else {
     setTitle("Game In Progress");
     if (myID == state.player1)
       message.setText(
           "You: "
               + state.score1
               + " pts "
               + state.KO1
               + " KOs Opponent: "
               + state.score2
               + " pts "
               + state.KO2
               + " KOs");
     else
       message.setText(
           "You: "
               + state.score2
               + " pts "
               + state.KO2
               + " KOs Opponent: "
               + state.score1
               + " pts "
               + state.KO1
               + " KOs");
   }
 }