예제 #1
0
 private void startGame() {
   timer.setDelay(INITIAL_DELAY);
   timer.setPaused(false);
   start_newgame_butt.setLabel("Start New Game");
   pause_resume_butt.setEnabled(true);
   pause_resume_butt.setLabel("Pause");
   pause_resume_butt.validate();
   sounds.playSoundtrack();
 }
예제 #2
0
 public void stop() {
   pauseGame();
   synchronized (timer) {
     timer.stop();
   }
   timer = null;
 }
예제 #3
0
  public void start() {
    timer =
        new Timer(
            INITIAL_DELAY,
            new ActionListener() {
              public void actionPerformed(ActionEvent ae) {
                synchronized (timer) {
                  if (cur_piece.canStepDown()) {
                    cur_piece.cut();
                    cur_piece.stepDown();
                    cur_piece.paste();

                    if (timer.isFast()) score_label.addValue(1);
                  } else {
                    timer.setFast(false);

                    if (!cur_piece.isTotallyOnGrid()) gameOver();
                    else {
                      removeFullRows();
                      installNewPiece();
                    }
                  }
                }
                game_grid.repaint();
              }
            });
    timer.start();
  }
예제 #4
0
 private void gameOver() {
   System.out.println("Game Over!");
   timer.setPaused(true);
   pause_resume_butt.setEnabled(false);
   int score = Integer.parseInt(score_label.getText());
   int high_score =
       high_score_label.getText().length() > 0 ? Integer.parseInt(high_score_label.getText()) : 0;
   if (score > high_score) high_score_label.setText("" + score);
   sounds.playGameOverSound();
 }
예제 #5
0
  void animate() {
    dim = getSize();
    size = (int) (Math.min(dim.height, dim.width) / 2.2);
    timer.tell_time();
    if (timer.time_diff == 0) return; // not enought time has passed, dont animate-crach fix
    dragged_speed = dragged_vec.sub(last_dragged_vec).div(timer.time_diff);
    last_dragged_vec = dragged_vec;
    if (dragged_ball != -1) {
      balls.get2(dragged_ball).pos = dragged_vec.add(find_offset).trim(-1, 1);
      balls.get2(dragged_ball).speed = dragged_speed;
    }

    balls = new WorldAnimate().calc_new_frame(balls, springs, RADIUS, timer);
  }
예제 #6
0
  private void removeFullRows() {
    int n_full = countFullRows();
    score_label.addValue((int) (10 * Math.pow(2, n_full) - 10));
    if (n_full == 0) return;

    sounds.playDestroyRows(n_full);

    if (num_rows_deleted / DELETED_ROWS_PER_LEVEL
        != (num_rows_deleted + n_full) / DELETED_ROWS_PER_LEVEL) {
      timer.faster();
      level_label.addValue(n_full / DELETED_ROWS_PER_LEVEL + 1);
      level_label.repaint();
    }

    rows_deleted_label.addValue(n_full);
    num_rows_deleted += n_full;

    for (int i = ROWS - 1; i >= 0; i--) while (rowIsFull(i)) removeRow(i);

    game_grid.repaint();
  }
예제 #7
0
 private void resumeGame() {
   timer.setPaused(false);
   pause_resume_butt.setLabel("Pause");
   sounds.playSoundtrack();
 }
예제 #8
0
 private void pauseGame() {
   timer.setPaused(true);
   pause_resume_butt.setLabel("Resume");
   sounds.stopSoundtrack();
 }
예제 #9
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  public LJ3MDApp() {
    tNum.setHorizontalAlignment(JTextField.CENTER);
    tTemp.setHorizontalAlignment(JTextField.CENTER);
    tRho.setHorizontalAlignment(JTextField.CENTER);
    tSpeed.setHorizontalAlignment(JTextField.CENTER);

    tAvK.setHorizontalAlignment(JTextField.RIGHT);
    tAvU.setHorizontalAlignment(JTextField.RIGHT);
    tAvp.setHorizontalAlignment(JTextField.RIGHT);

    float[] aveKing = new float[501];
    float[] avePot = new float[501];
    float[] aveEn = new float[501];

    JFrame box = new JFrame();
    box.setLayout(new BorderLayout());
    box.setSize(1000, 1000);
    box.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    cpnl = new JPanel(); // create a panel for controls
    cpnl.setLayout(new GridLayout(18, 2));
    box.add(cpnl, BorderLayout.EAST);

    // add controls
    cpnl.add(bStart);
    bStart.addActionListener(this);

    cpnl.add(bReset);
    bReset.addActionListener(this);

    cpnl.add(new JLabel(" N:"));
    tNum.addActionListener(this);
    cpnl.add(tNum);

    cpnl.add(new JLabel(" Density (\u03c1):"));
    tRho.addActionListener(this);
    cpnl.add(tRho);

    cpnl.add(new JLabel(" Steps/frame:"));
    tSpeed.addActionListener(this);
    cpnl.add(tSpeed);

    cpnl.add(bTstat);
    bTstat.addActionListener(this);

    cpnl.add(bPot);
    bPot.addActionListener(this);

    cpnl.add(new JLabel(" < K/N > :"));
    tAvK.setEditable(false);
    cpnl.add(tAvK);

    cpnl.add(new JLabel(" Temperature:"));
    tTemp.setEditable(false);
    cpnl.add(tTemp);

    cpnl.add(new JLabel(" < U/N > :"));
    tAvU.setEditable(false);
    cpnl.add(tAvU);

    cpnl.add(new JLabel(" < pressure > :"));
    tAvp.setEditable(false);
    cpnl.add(tAvp);

    cpnl.add(bRetime);
    bRetime.addActionListener(this);

    spnl = new JPanel(); // create a panel for status
    box.add(spnl, BorderLayout.SOUTH);
    lStatus.setFont(new Font("Courier", 0, 12));
    spnl.add(lStatus);

    canvas = new XYZCanvas();
    box.add(canvas, BorderLayout.CENTER);

    timer = new Timer(delay, this);
    timer.start();
    //        timer.stop();
    box.setVisible(true);
  }
예제 #10
0
파일: LJ3MDApp.java 프로젝트: eskilj/mvp
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();
    if (src == timer) {
      for (int i = 0; i < speed; i++) // integrate a few steps
      md.vv();
      repaint();
      return;
    }

    boolean adjCanvasScale = false;

    if (src == bTstat) md.thermostat = !md.thermostat;

    if (src == bPot) {
      md.ljPotential = !md.ljPotential;
      md.clearData();

      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    if (src == tTemp || src == bReset) {
      double kT = Double.parseDouble(tTemp.getText().trim());
      if (kT < 1e-8) {
        kT = 1e-8;
        tTemp.setText("  " + kT);
      }
      md.kT = kT;
      md.clearData();
    }

    if (src == tRho || src == bReset) {
      double rho = Double.parseDouble(tRho.getText().trim());
      if (rho < 1e-3) {
        rho = 1e-3;
        tRho.setText("   " + rho);
      }
      if (rho > 1.2) {
        rho = 1.2;
        tRho.setText("   " + rho);
      }
      md.setDensity(rho);
      md.clearData();
      adjCanvasScale = true;
    }

    if (src == tSpeed || src == bReset) {
      speed = Integer.parseInt(tSpeed.getText().trim());
      if (speed < 1) {
        speed = 1;
        tSpeed.setText("   " + speed);
      }
    }

    if (src == bRetime) md.clearData();

    if (src == bStart) {
      boolean on = bStart.isSelected();
      if (on) {
        timer.restart();
        bStart.setText("Pause");
      } else {
        timer.stop();
        bStart.setText("Resume");
      }
    }

    if (src == tNum) {
      int n = Integer.parseInt(tNum.getText().trim());
      if (n < 2) {
        n = 2;
        tNum.setText(" " + n);
      }
      md.N = n;
      md.init(md.rho);
      adjCanvasScale = true;
    }

    if (src == bReset) {
      if (timer.isRunning()) timer.stop();
      bStart.setSelected(false);
      bStart.setText("Start");
      md.init(md.rho);
    }

    canvas.refresh(md.getXWrap(), md.N, true, adjCanvasScale);

    repaint();
  }
 /** Override the applet's stop method */
 public void stop() {
   timer.stop(); // Suspend clock
 }
 /** Override the applet's start method */
 public void start() {
   timer.start(); // Resume clock
 }