⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 runrandombirds.java

📁 本程序是用多线程实现了打飞鸟游戏程序
💻 JAVA
字号:
/*
 * RunRandomBirds.java
 *
 * Created on 2001年12月27日, 下午4:59
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package shoot_birds;

import java.util.Random;
import javax.swing.JPanel;

/**
 *
 * @author open
 */
public class RunRandomBirds implements Runnable{
    
    /** Creates a new instance of RunRandomBirds */
    public RunRandomBirds(birdpanel panel) {
        this.panel=panel;
    }

    public void run() {
        try
        { 
            /*Random rand=new Random();
             * rand.nextInt()
             * 产生随机数
             * 得到鸟的飞行速度等
             * */
        	Random rand=new Random();
            for(int i=0;i<50;i++)
            {
                int y=rand.nextInt()%100;
                if(y<0)
                    y=-y;
                int delay1=rand.nextInt()%1000;
                delay1=Math.abs(delay1);
                if(delay1==0)
                   delay1=100;
                int delay=rand.nextInt()%100;
                 delay=Math.abs(delay);
                if(delay<=20)
                   delay+=20;
                bird b = new bird(0,y,10);
                panel.add(b);
                Runnable r = new RuanableThread(b, panel,delay);
                Thread t = new Thread(r);
                t.start();
                Thread.sleep(delay1);
               
            }
            
        }catch(Exception e)
        {
            
        }
    }
    private birdpanel panel;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -