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

📄 fw.js

📁 “星际争霸”地球人都知道吧
💻 JS
📖 第 1 页 / 共 2 页
字号:
var fw1=new fw(),sys=new Array(),udf=new Array(),race=new Array(),cRace="red"
fw_ini()
function fw_ini(){
	sys.minePos=""
	sys.vesPos=""
	
	race["red"]=createClass("mine:50;ves:0;man:4;supply:8;keyBuild:,;hq:")
	race["blue"]=createClass("mine:50;ves:0;man:4;supply:8;keyBuild:,;hq:")
	
	udf["mine"]=createClass("type:block;size:1,1;movepos:-1,-16;selpos:-4,16,48,30")
	udf["ves"]=createClass("type:block;size:3,2;movepos:2,3;selpos:-6,0,124,60")

	udf["0_hq"]=createClass("type:build;wh:127,101;size:3,3;movepos:0,-14;selpos:-8,22,140,80;hppos:5,86,130;hp:1500;btime:3;madelist:0_scv")
	udf["0_supply"]=createClass("type:build;wh:87,70;size:2,2;movepos:-2,-9;selpos:-5,18,95,56;hppos:2,62,94;hp:750;btime:2;mine:100;ves:0")
	udf["0_refinery"]=createClass("type:build;wh:125,95;size:3,2;movepos:-2,-32;selpos:-8,22,140,80;hppos:5,86,130;hp:750;btime:2;mine:100;ves:0")
	udf["0_barrack"]=createClass("type:build;wh:125,110;size:3,3;movepos:-2,-18;selpos:-8,34,140,80;hppos:5,86,130;hp:1000;btime:3;mine:150;ves:0;madelist:0_marine,0_firebat,0_medic")
	udf["0_academy"]=createClass("type:build;wh:95,95;size:2,2;movepos:-10,-32;selpos:-2,38,100,60;hppos:2,66,100;hp:600;btime:3;mine:150;ves:0")
	udf["0_gun_tower"]=createClass("type:build;wh:95,58;size:2,2;movepos:-8,2;selpos:-8,22,140,80")
	udf["0_missile"]=createClass("type:build;wh:41,50;size:1,1;movepos:0,-20;selpos:-8,22,140,80")
		
	udf["0_scv"]=createClass("type:unit;kind:ground;mvstyle:shift;speed:4;wh:48;selpos:5,12,36,24;hppos:1,33,35;hp:60;mine:50;ves:0")
	udf["0_marine"]=createClass("type:unit;kind:ground;mvstyle:walk;speed:3;wh:32;selpos:5,15,20,16;hppos:1,20,24;hp:40;mine:50;ves:0;range:4")
	udf["0_firebat"]=createClass("type:unit;kind:ground;mvstyle:walk;speed:3;wh:32;selpos:3,15,26,18;hppos:1,24,26;hp:50;mine:50;ves:25;range:1")
	udf["0_medic"]=createClass("type:unit;kind:ground;mvstyle:walk;speed:3;wh:32;selpos:3,15,26,18;hppos:1,24,26;hp:60;mine:25;ves:25")
	udf["0_tank"]=createClass("type:unit;kind:ground;speed:1;wh:72;selpos:10,16,50,40")
	udf["0_valture"]=createClass("type:unit;kind:ground;speed:1;wh:64;selpos:12,20,36,27")
	udf["0_wraith"]=createClass("type:unit;kind:air;speed:1;wh:48;selpos:12,16,27,20")
}
function createClass(k){
	var ao=new Array(),ak=k.split(";")
	for(var i in ak){
		ak[i]=ak[i].split(":")
		if(!isNaN(ak[i][1]))
			ak[i][1]=parseInt(ak[i][1])
		ao[ak[i][0]]=ak[i][1]
	}
	return ao
}
function showObj(ol){
	var a=ol.split(";"),i,j
	for(i in a){
		a[i]=a[i].split(",")
		for(j in a[i]){
			if(i==0&&a[i][j]!="")
				eval(a[i][j]).style.display=""
			if(i==1&&a[i][j]!="")
				eval(a[i][j]).style.display="none"
		}
	}
}
function fw(){
	//uList定义:[0]-block;[1]-mine;[2]-build;[3]-unit
	this.uList=new Array("","","","")
	//bList定义:[0]-mine;[1]-block and build;[2]-hold unit
	this.bList=new Array("","","")
	
	this.cEndPos=0
	this.maxID=0
	this.selUnit=""
	this.adp="1,0;1,1;0,1;-1,1;-1,0;-1,-1;0,-1;1,-1;1,0;1,1;0,1;-1,1;-1,0;-1,-1;0,-1;1,-1".split(";")
	for(var i=0;i<16;i++){
		this.adp[i]=this.adp[i].split(",")
		this.adp[i][0]=parseInt(this.adp[i][0])
		this.adp[i][1]=parseInt(this.adp[i][1])
	}
	this.iniMap=function(k){
		var l="",lm="",xi,yi,i,j,n
		var a=k.split(";"),uu,a_sz,a_mv,a_sl,a_hp,a_wh
		for(i in a){
			a[i]=a[i].split(",")
			if(a[i][0]=="size"){
				divSize.style.width =a[i][1]*40
				divSize.style.height =a[i][2]*30
			}
			else{
				xi=parseInt(a[i][2])
				yi=parseInt(a[i][3])
				uu=udf[a[i][1]]
				a_sl=uu.selpos.split(",")
				if(uu.type=="block"||uu.type=="build"){
					a_sz=uu.size.split(",")
					a_mv=uu.movepos.split(",")
					for(j=0;j<a_sz[0];j++){
						for(n=0;n<a_sz[1];n++){
							if(uu.type=="block")
								this.bList[0]+=";"+(xi+j)+","+(yi+n)
							if(uu.type=="build")
								this.bList[1]+=";"+(xi+j)+","+(yi+n)
							//this.paint(new pt(xi+j,yi+n),"black")
						}
					}
				}
				if(a[i][1]=="mine")
					sys.minePos+=";"+xi+","+yi
				if(a[i][1]=="ves")
					sys.vesPos+=";"+xi+","+yi
				if(uu.type=="block"){
					this.uList[1]+=",unit_"+a[i][0]
					l+="<span id=unit_"+a[i][0]+" name="+a[i][1]+" uType=block px="+xi+" py="+yi+" pw="+a_sz[0]+" ph="+a_sz[1]+" style='left:"+(xi*40+parseInt(a_mv[0]))+";top:"+(yi*30+parseInt(a_mv[1]))+";z-index:"+yi+"'>"
					l+="<v:oval coordsize='21600,21600' strokecolor=#F2F230 style='visibility:hidden;position:absolute;left:"+a_sl[0]+";top:"+a_sl[1]+";width:"+a_sl[2]+";height:"+a_sl[3]+"'><v:fill opacity =0></v:fill></v:oval>"
					l+="<img src=block/"+a[i][1]+".gif>"
					l+="</span>"
					lm+="<hr id=unit_"+a[i][0]+"_mini color=#00E4FC style=left:"+(xi*2)+";top:"+(yi*2)+";width:"+(a_sz[0]*2)+";height:"+(a_sz[1]*2)+">"
				}
				if(uu.type=="build"){
					a_hp=uu.hppos.split(",")
					a_wh=uu.wh.split(",")
					var s_m=""
					if(a[i][5]!=0&&a[i][1]=="0_refinery")
						s_m="<img src='block/ves_gas.gif' style=left:55;top:-20>"
					this.uList[2]+=",unit_"+a[i][0]
					l+="<span id=unit_"+a[i][0]+" name="+a[i][1]+" uType=build hp="+uu.hp+" chp="+uu.hp+" bType='' bn="+(a[i][5]==0 ? 0 : -1)+"  mn=-1 sx="+a_sz[0]+" sy="+a_sz[1]+" px="+xi+" py="+yi+" pw="+a_sz[0]+" ph="+a_sz[1]+" aimu='' race='"+a[i][4]+"' style='left:"+(xi*40+parseInt(a_mv[0]))+";top:"+(yi*30+parseInt(a_mv[1]))+";z-index:"+yi+"'>"
					l+="<v:oval coordsize='21600,21600' strokecolor="+(a[i][4]==cRace ? "#10FC18" : "#F83A3A")+" style='visibility:hidden;position:absolute;left:"+a_sl[0]+";top:"+a_sl[1]+";width:"+a_sl[2]+";height:"+a_sl[3]+"'><v:fill opacity =0></v:fill><span class=hpbar style='left:"+a_hp[0]+";top:"+a_hp[1]+";width:"+a_hp[2]+"'><hr size=3 color=#249824 style=width:"+(a[i][5]==0 ? 0 : "100%")+"></span></v:oval>"
					l+="<span style=width:"+a_wh[0]+";height:"+a_wh[1]+";overflow:hidden><img src=build/"+a[i][1]+"_"+a[i][4]+".gif style=left:"+(a[i][5]==0 ? -2*a_wh[0] : 0)+"></span>"
					l+="<span>"+s_m+"</span>"
					l+="</span>"
					lm+="<hr id=unit_"+a[i][0]+"_mini color='"+a[i][4]+"' style=left:"+(xi*2)+";top:"+(yi*2)+";width:"+(a_sz[0]*2)+";height:"+(a_sz[1]*2)+">"
					if(a[i][1]=="0_hq"){
						race[a[i][4]].hq=(xi+1)+","+(yi+1)
					}
				}
				if(uu.type=="unit"){
					a_hp=uu.hppos.split(",")
					this.uList[3]+=",unit_"+a[i][0]
					l+="<span id=unit_"+a[i][0]+" name="+a[i][1]+" uType=unit hp="+uu.hp+" chp="+uu.hp+" mvstyle='"+uu.mvstyle+"' px="+xi+" py="+yi+" cw="+uu.wh+" race='"+a[i][4]+"' class='unit_"+uu.kind+"' speed='"+uu.speed+"' path='' aimPos='' aimn=0 aimu='' face='' pose=0 tmMove=0 tmDir=0 style='left:"+(xi*40+(40-uu.wh)/2)+";top:"+(yi*30+(30-uu.wh)/2)+";z-index:"+yi+"'>"
					l+="<v:oval coordsize='21600,21600' strokecolor="+(a[i][4]==cRace ? "#10FC18" : "#F83A3A")+" style='visibility:hidden;position:absolute;left:"+a_sl[0]+";top:"+a_sl[1]+";width:"+a_sl[2]+";height:"+a_sl[3]+"'><v:fill opacity =0></v:fill><span class=hpbar style='left:"+a_hp[0]+";top:"+a_hp[1]+";width:"+a_hp[2]+"'><hr size=3 color=#249824 style=width:100%></span></v:oval>"
					l+="<span style=width:"+uu.wh+";height:"+uu.wh+";overflow:hidden><img src=unit/"+a[i][1]+"_"+a[i][4]+".gif style=top:"+(-parseInt(5*Math.random())*uu.wh)+"></span>"
					l+="<span></span></span>"
					lm+="<hr id=unit_"+a[i][0]+"_mini color='"+a[i][4]+"' style=left:"+(xi*2)+";top:"+(yi*2)+";width:2;height:2>"
				}
			}
		}
		this.maxID=parseInt(a[i][0])+1
		if(sys.minePos.slice(0,1)==";")
			sys.minePos=sys.minePos.slice(1)
		if(sys.vesPos.slice(0,1)==";")
			sys.vesPos=sys.vesPos.slice(1)
		if(this.bList[0].slice(0,1)==";")
			this.bList[0]=this.bList[0].slice(1)
		if(this.bList[1].slice(0,1)==";")
			this.bList[1]=this.bList[1].slice(1)
		if(this.uList[0].slice(0,1)==",")
			this.uList[0]=this.uList[0].slice(1)
		if(this.uList[1].slice(0,1)==",")
			this.uList[1]=this.uList[1].slice(1)
		if(this.uList[2].slice(0,1)==",")
			this.uList[2]=this.uList[2].slice(1)
		if(this.uList[3].slice(0,1)==",")
			this.uList[3]=this.uList[3].slice(1)
		divMain.insertAdjacentHTML("beforeend",l)
		mini_map.insertAdjacentHTML("afterbegin",lm)
	}
	this.delUnit=function(u){
		var u_mini=eval(u.id+"_mini")
		if(this.selUnit==u.id)
			this.selUnit=""
		for(i=0;i<u.pw;i++){
			for(j=0;j<u.ph;j++){
				this.bList[1]=(";"+this.bList[1]+";").replace(";"+(parseInt(u.px)+i)+","+(parseInt(u.py)+j)+";",";").slice(1,-1)
			}
		}
		this.uList[2]=(","+this.uList[2]+",").replace(","+u.id+",",",").slice(1,-1)
		this.uList[3]=(","+this.uList[3]+",").replace(","+u.id+",",",").slice(1,-1)
		this.selUnit=(","+this.selUnit+",").replace(","+u.id+",",",").slice(1,-1)
		u.removeNode(true)
		u_mini.removeNode(true)
	}
	this.uInPos=function(p){
		var u,o,a=(this.uList[1]+","+this.uList[2]+","+this.uList[3]).split(",")
		var pw,ph
		for(var i in a){
			o=eval(a[i])
			pw=o.pw==null ? 1 : o.pw
			ph=o.ph==null ? 1 : o.ph
			if(p.x-o.px<pw&&p.x-o.px>=0&&p.y-o.py<ph&&p.y-o.py>=0){
				u=o
				if(u.name!="ves")
					break
			}
		}
		return u
	}
	this.selRange=function(sp,ep){
		var l="",u,a,i
		if(fw1.selUnit!=""){
			a=fw1.selUnit.split(",")
			for(i in a){
				u=eval(a[i])
				u.children(0).style.visibility="hidden"
			}
		}
		a=this.uList[3].split(",")
		for(i=0;i<a.length;i++){
			u=eval(a[i])
			if(u.race==cRace&&((u.px>=sp.x&&ep.x>=u.px)||(u.px<=sp.x&&ep.x<=u.px))&&((u.py>=sp.y&&ep.y>=u.py)||(u.py<=sp.y&&ep.y<=u.py))){
				u.children(0).style.visibility=""
				l+=u.id+","
			}
		}
		l=l.slice(0,-1)
		if(sp.v==ep.v&&l==""){
			u=this.uInPos(sp)
			if(u!=null){
				u.children(0).style.visibility=""
				l=u.id
			}
		}
		fw1.selUnit=l
	}
	this.setUBlock=function(u){
		var u
		this.bList[2]=""
		al=this.uList[3].split(",")
		for(i in al){
			u=eval(al[i])
			if(u.path==""&&(","+this.selUnit+",").indexOf(","+u.id+",")==-1)
				this.bList[2]+=u.px+","+u.py+";"
		}
		this.bList[2]=";"+this.bList[2]
		if(u!=null)
			this.bList[2]=this.bList[2].replace(";"+u.px+","+u.py+";",";")
	}
	this.go=function(ep0){
		if(this.selUnit=="")
			return
		var sp=new pt(),ep=new pt()
		var al,a,i,s,rv,epu,epuName,u
		this.setUBlock()
		this.cEndPos=0
		al=fw1.selUnit.split(",")
		for(i in al){
			u=eval(al[i])
			epu=this.uInPos(ep0)
			epuName=epu==null ? "" : epu.name
			u.aimPos=""
			u.task=""
			u.aimu=""
			u.children(2).innerHTML=""
			u.children(1).style.display=""
			if(epu!=null){
				if((u.name=="0_firebat"||u.name=="0_marine")&&epu.race!=cRace){
					u.aimu=epu.id
					u.task="attack"
				}
			}
			sp.setv(u.px,u.py)
			this.bList[2]=fw1.bList[2].replace(";"+sp.v+";",";")
			s=""
			if(u.className=="airUnit")
				s="airUnit"
			if(u.name=="0_scv"&&epuName=="mine")
				s="mining"
			rv=this.getEndPos(ep0,s)
			if(rv[0]=="")
				return
			if(rv[1]!="")
				u.aimu=rv[1]
			ep.setv(rv[0])
			if(u.className=="airUnit")
				u.path=ep.v
			else{
				if(this.inBlock(ep))
					return
				l=this.getPath(sp,ep)
				u.path=l
				if(u.name=="0_scv"){
					a="2,0;2,1;1,2;0,2;-1,2;-2,1;-2,0;-2,-1;-1,-2;0,-2;1,-2;2,-1".split(";")
					var n=parseInt(12*Math.random())
					a[n]=a[n].split(",")
					sp.setv(race[u.race].hq)
					sp.setv(sp.x+parseInt(a[n][0]),sp.y+parseInt(a[n][1]))
					if(epuName=="mine"){
						u.aimPos=u.aimu+",400;"+sp.v+";"+ep.v
						u.task="mining"
					}
					if(epuName=="0_refinery"){
						if(epu.bn==-1){
							u.aimPos=epu.id+",100;"+sp.v+";"+ep.v
							u.task="gasing"
						}
					}
				}
			}
		}
	}
	this.setSpark=function(u){
		var s="left:-10;top:0"
		if(u.face==0)
			s="left:5;top:-10"
		if(u.face=="1f")
			s="left:-5;top:-10"
		if(u.face==1)
			s="left:18;top:-10"
		if(u.face==2)
			s="left:18;top:0"
		if(u.face==3)
			s="left:18;top:15"
		if(u.face=="3f")
			s="left:-5;top:15"
		if(u.face==4)
			s="left:0;top:15"
		u.children(2).innerHTML="<img src=unit/0_scv_spark.gif style="+s+">"
	}
	this.setFight=function(u){
		var l="",a_fpos=new Array(),p=new pt(0,0)
		a_fpos=createClass("0_marine_4:0,-3;0_marine_3:5,-1;0_marine_3f:-4,-1;0_marine_2:4,0;0_marine_2f:-4,0;0_marine_1:4,0;0_marine_1f:-4,0;0_marine_0:6,-4;0_firebat_4:6,0;0_firebat_0:-13,-64;0_firebat_1:5,-56;0_firebat_1f:-30,-56;0_firebat_2:4,-35;0_firebat_2f:-65,-35;0_firebat_3:4,0;0_firebat_3f:-57,0")
		if(a_fpos[u.name+"_"+u.face]!=null)
			p.setv(a_fpos[u.name+"_"+u.face])
		l="<img src=unit/"+u.name+"_"+u.race+"_atk0.gif style=left:"+p.x+";top:"+p.y+">"
		if(u.face==1)
			l="<img src=unit/"+u.name+"_"+u.race+"_atk1.gif style=left:"+p.x+";top:"+p.y+">"
		if(u.face=="1f")
			l="<img src=unit/"+u.name+"_"+u.race+"_atk1.gif style=filter:fliph;left:"+p.x+";top:"+p.y+">"
		if(u.face==2)
			l="<img src=unit/"+u.name+"_"+u.race+"_atk2.gif style=left:"+p.x+";top:"+p.y+">"
		if(u.face=="2f")
			l="<img src=unit/"+u.name+"_"+u.race+"_atk2.gif style=filter:fliph;left:"+p.x+";top:"+p.y+">"
		if(u.face=="3")
			l="<img src=unit/"+u.name+"_"+u.race+"_atk3.gif style=left:"+p.x+";top:"+p.y+">"
		if(u.face=="3f")
			l="<img src=unit/"+u.name+"_"+u.race+"_atk3.gif style=filter:fliph;left:"+p.x+";top:"+p.y+">"
		if(u.face=="4")
			l="<img src=unit/"+u.name+"_"+u.race+"_atk4.gif style=left:"+p.x+";top:"+p.y+">"
		u.children(1).style.display="none"
		u.children(2).innerHTML=l
	}
	this.getMinLen=function(u,aimu){
		var n0=1000,pw,ph,n,ep=new pt(),dp=new pt(),a_rv=new Array()
		pw=aimu.pw==null ? 1 : aimu.pw
		ph=aimu.ph==null ? 1 : aimu.ph
		for(var i=0;i<pw;i++){
			for(var j=0;j<ph;j++){
				ep.setv(parseInt(aimu.px)+i,parseInt(aimu.py)+j)
				n=Math.max(Math.abs(ep.x-u.px),Math.abs(ep.y-u.py))
				if(n<n0){
					n0=n
					dp.setv(ep.x==u.px ? 0 : (ep.x>u.px ? 1 : -1),ep.y==u.py ? 0 : (ep.y>u.py ? 1 : -1))
				}
			}
		}
		a_rv[0]=n0
		a_rv[1]=dp.v
		return a_rv
	}
	this.move=function(u){
		var dp=new pt(),sp=new pt(),ep=new pt()
		if(u.path==""){
			sp.setv(u.px,u.py)
			if(u.mvstyle=="walk"){
				u.children(1).scrollLeft=0
			}
			if(u.task=="attack"){
				if((","+this.uList[2]+","+this.uList[3]+",").indexOf(","+u.aimu+",")==-1){
					u.task=""
					u.children(1).style.display=""
					u.children(2).innerHTML=""
				}
				else{

⌨️ 快捷键说明

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