Exemplo n.º 1
1
  /** 实现计时功能 */
  @SuppressWarnings("deprecation")
  public void run() {
    try {
      Thread.sleep(1000); // 延迟1s
    } catch (InterruptedException e1) {
      e1.printStackTrace();
    }
    while (true) {
      if (blacktime > 0 && whitetime > 0 && blackOneTime > 0 && whiteOneTime > 0) {
        if (cb.isBlack) {
          whiteOneTime = maxOneStepTime;
          blacktime--;
          blackOneTime--;
        } else {
          blackOneTime = maxOneStepTime;
          whitetime--;
          whiteOneTime--;
        }
        blackMessage = this.initTime(blacktime);
        whiteMessage = this.initTime(whitetime);
        if (blackOneTime < 5 || whiteOneTime < 5) {
          v.play("clock");
        }
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
      if (blackOneTime == 0 || blacktime == 0) {
        JOptionPane.showMessageDialog(cb, "黑方时间到,白方胜");
        cb.message = "黑方时间到,白方胜";
        v.play("end");
        cb.changeColor = true;
        cb.canPlay = false;
        cb.whiteWin++;
        rp.ready.setText("准备");
        rp.isReady = false;
        t.suspend();
      }
      if (whiteOneTime == 0 || whitetime == 0) {
        JOptionPane.showMessageDialog(cb, "白方时间到,黑方胜");
        cb.message = "白方时间到,黑方胜";
        v.play("end");
        cb.changeColor = true;
        cb.canPlay = false;
        cb.blackWin++;
        rp.ready.setText("准备");
        rp.isReady = false;
        t.suspend();
      }

      cb.repaint();
    }
  }
Exemplo n.º 2
1
  /**
   * 实现对认输的处理
   *
   * @param dis
   */
  @SuppressWarnings("deprecation")
  public void giveUpAnswer(DataInputStream dis) {
    try {
      boolean isplayer1 = dis.readBoolean();
      boolean isplayer2 = dis.readBoolean();
      cb.changeColor = true;
      cb.canPlay = false;
      v.play("end");
      t.suspend();
      rp.ready.setText("准备");
      rp.isReady = false;
      if (isplayer1 == true && isplayer2 == false) {
        JOptionPane.showMessageDialog(cb, "黑方已经认输,白方胜");
        cb.message = "黑方已经认输,白方胜";
        cb.whiteWin++;
      }
      if (isplayer2 == true && isplayer1 == false) {
        JOptionPane.showMessageDialog(cb, "白方已经认输,黑方胜");
        cb.message = "白方已经认输,黑方胜";
        cb.blackWin++;
      }

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 3
1
  public boolean mouseDown(Event e, int x, int y) {
    if (suspended) {
      animate.resume();
      suspended = false;
    } else {
      animate.suspend();
      suspended = true;
    }

    return true;
  }
Exemplo n.º 4
1
 public void pausar() {
   if (t != null) t.suspend();
   if (soltarCoco != null) soltarCoco.suspend();
   suspender = true;
   laberinto1.stopCocos();
   if (laberinto1.areComidos())
     try {
       cocoComido.Pausa();
     } catch (Exception ex) {
       Logger.getLogger(ComeCocosView.class.getName()).log(Level.SEVERE, null, ex);
     }
   else if (laberinto1.areweakCocos())
     try {
       cocoWeak.Pausa();
     } catch (Exception ex) {
       Logger.getLogger(ComeCocosView.class.getName()).log(Level.SEVERE, null, ex);
     }
   else
     try {
       cocoNormal.Pausa();
     } catch (Exception ex) {
       Logger.getLogger(ComeCocosView.class.getName()).log(Level.SEVERE, null, ex);
     }
 }
Exemplo n.º 5
1
 /** 实现对求和的处理 */
 @SuppressWarnings("deprecation")
 public void drawAnswer() {
   if (answer == 0) {
     cb.message = "双方言和,平局!";
     cb.changeColor = true;
     cb.canPlay = false;
     cb.su.update(0, 0, HallPlayerPanel.nickname);
     rp.ready.setText("准备");
     rp.isReady = false;
     t.suspend();
     v.play("end");
     JOptionPane.showMessageDialog(cb, "对方同意了你的求和!");
   }
   if (answer != 0) {
     JOptionPane.showMessageDialog(cb, "对方拒绝了你的请求!");
   }
   answer = 3;
 }