📄 createcar.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */package fivestarcross;import java.util.Random;/** * * @author Administrator */public class CreateCar implements Runnable{ CreateCar(MainPanel aMainPanel,int aTime,float[][] traffic){ p=aMainPanel; onetime=aTime; bounds=new int[20]; setTraffic(traffic); } public void run(){ while(true){ if(p.Player==0){ Random random=new Random(); temp=random.nextInt(bounds[19]); if(temp>=0&&temp<=bounds[0]){In=0;Out=1;} else if(temp>bounds[0]&&temp<=bounds[1]){In=0;Out=2;} else if(temp>=bounds[1]&&temp<=bounds[2]){In=0;Out=3;} else if(temp>=bounds[2]&&temp<=bounds[3]){In=0;Out=4;} else if(temp>=bounds[3]&&temp<=bounds[4]){In=1;Out=0;} else if(temp>=bounds[4]&&temp<=bounds[5]){In=1;Out=2;} else if(temp>=bounds[5]&&temp<=bounds[6]){In=1;Out=3;} else if(temp>=bounds[6]&&temp<=bounds[7]){In=1;Out=4;} else if(temp>=bounds[7]&&temp<=bounds[8]){In=2;Out=0;} else if(temp>=bounds[8]&&temp<=bounds[9]){In=2;Out=1;} else if(temp>=bounds[9]&&temp<=bounds[10]){In=2;Out=3;} else if(temp>=bounds[10]&&temp<=bounds[11]){In=2;Out=4;} else if(temp>=bounds[11]&&temp<=bounds[12]){In=3;Out=0;} else if(temp>=bounds[12]&&temp<=bounds[13]){In=3;Out=1;} else if(temp>=bounds[13]&&temp<=bounds[14]){In=3;Out=2;} else if(temp>=bounds[14]&&temp<=bounds[15]){In=3;Out=4;} else if(temp>=bounds[15]&&temp<=bounds[16]){In=4;Out=0;} else if(temp>=bounds[16]&&temp<=bounds[17]){In=4;Out=1;} else if(temp>=bounds[17]&&temp<=bounds[18]){In=4;Out=2;} else if(temp>=bounds[18]&&temp<=bounds[19]){In=4;Out=3;} else return; if(In!=Out){ num=In*5+Out; if(p.queue[num].size()!=0)preCar=(Car)p.queue[num].get(p.queue[num].size()-1); else{preCar=null;} c=new Car(p.begin[num],p.turn[num],p.stop[num],In,Out,p.angel[In],preCar); p.queue[num].add(c); Runnable r=new CarMove(p,c); Thread t=new Thread(r); t.setPriority(Thread.MAX_PRIORITY); t.start();} } try{ Thread.sleep((int)(3600.0f/bounds[19]*onetime)); }catch(InterruptedException e){} } } public void setonetime(int aTime){ onetime=aTime; } public void setTraffic(float[][] newTraffic){ int k=0; int total=0; for(int i=0;i<5;i++) for(int j=0;j<5;j++){ if(i!=j){ total+=newTraffic[i][j]; bounds[k++]=total; } } } int temp,In,Out,num,onetime; Car c,preCar; MainPanel p; int[] bounds;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -