statthread.java
来自「本程序是用多线程实现了打飞鸟游戏程序」· Java 代码 · 共 93 行
JAVA
93 行
/*
* StatThread.java
*
* Created on 2007年12月28日, 下午1:33
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package shoot_birds;
import java.applet.Applet;
import java.applet.AudioClip;
import java.util.ArrayList;
import javax.swing.JOptionPane;
/**
*
* @author open
*/
public class StatThread implements Runnable
{
/** Creates a new instance of StatThread */
public StatThread(birdpanel panel,mainFrame frame)
{
this.panel=panel;
this.frame=frame;
}
@SuppressWarnings("deprecation")
public void run()
{
try{
while(true)
{
birds=panel.getList();
remain_bird=50;
deadbird=0;
for(bird b:birds)
{
if(b.isDead()||b.isLeave())
{
remain_bird--;
}
if(b.isDead())
deadbird++;
}
frame.getBirdNumText().setText(""+remain_bird+"只");
frame.getBulletNumText().setText(""+Bullet.getInstance().getNum()+"发");
frame.getField3().setText(""+deadbird+"只");
Thread.sleep(100);
/*
* 背景鸟叫声
* */
if(remain_bird>0)
{
AudioClip clip=Applet.newAudioClip(getClass().getResource("bird.wav"));
clip.play();
try {
Thread.sleep(100);
clip.stop();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
else if(remain_bird==0)
{
if(deadbird >= 25)
{
JOptionPane.showMessageDialog(null, "游戏结束!"+"\n"+"您的花费了"+(100-Bullet.getInstance().getNum())+"发子弹"+"打死了"+deadbird+"只鸟"+"\n你真是神枪手!");
System.exit(0);
}
else
{
JOptionPane.showMessageDialog(null, "游戏结束!"+"\n"+"您的花费了"+(100-Bullet.getInstance().getNum())+"发子弹"+"打死了"+deadbird+"只鸟");
System.exit(0);
}
}
}
}catch(Exception e){ System.out.println("抛出这个异常不知道是怎么回事?");}
}
private birdpanel panel;
private ArrayList<bird> birds;
private int remain_bird=50,deadbird=0;
private mainFrame frame;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?