您的位置:首页 > Web前端 > JavaScript

【编程游戏】贺岁放礼花。(点燃34楼zjsfdxbao的焰火)

2008-12-25 15:20 274 查看
function viewPage(html) {
var page = window.open('', '', '');
page.opener = null;
page.document.write(html);
page.document.close();
}

【编程游戏】贺岁放礼花。(第一名奖励10000可用分)
作者:


点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

<html>
<head>
<title>【编程游戏】贺岁放礼花。</title>
</head>
<body>
<script>
var FireColor = ["red","blue","yellow","orange","pink"];
var FireStyle = ["¤","●","○","◎","▲"];
var StarStyle = ["☆","★","※","∵","◆"];
function xo()
{
this.x=0;this.y=0;this.power=Math.floor(Math.random()*arguments[0]+arguments[1]);
}
function star(c)
{
var handle=this;
xo.call(this,100,0);
this.star=StarStyle[Math.floor(Math.random()*4)];
this.angle=2*Math.PI*Math.random()+1;
this.o=document.createElement("span");
document.body.appendChild(this.o);
this.o.innerHTML=this.star;
this.style=this.o.style;
this.color=c;
this.exist=false;
with(this.style)
{
visibility="hidden";
position="absolute";
color=this.color;
}
this.move=function()
{
if(this.y<this.power)
{
this.y+=2;
with(this.style)
{
top=this.y;
left=this.x+this.y*Math.sin(this.angle);
}
}else
{
this.clear();
}
}
this.burn=function(x,y)
{
this.style.left=this.x=x;
this.style.top=this.y=y;
}
this.shine=function(x,y)
{
this.burn(x,y);
this.style.visibility="visible";
this.gogo=setInterval(function(){handle.move()},17);
}
this.clear=function()
{
this.o.parentNode.removeChild(this.o);
clearInterval(this.gogo);
}
}
function Firework()
{
var handle=this;
xo.call(this,10,25);
this.color=FireColor[Math.floor(Math.random()*4)];
this.shape=FireStyle[Math.floor(Math.random()*4)];
this.starnum=Math.floor(Math.random()*7)+5;
this.star = new Array();
this.exist=true;
for(var i=0;i<this.starnum;i++)
{
this.star[i]=new star(this.color);
}
this.starnum=Math.floor(Math.random()*4)+4;
this.o = document.createElement("span");
document.body.appendChild(this.o);
this.o.innerHTML=this.shape;
this.style=this.o.style;
this.style.color=this.color;
this.style.position="absolute";
this.setX=function(x){this.style.left=x+"px";this.x=x;}
this.setY=function(y){this.style.top=y+"px";this.y=y;}
this.move=function()
{
this.y -=this.power/3;
if(this.y>this.power)
this.style.top=this.y + "px";
else
{
if(this.exist)this.clear();
}
}
this.fire=function()
{
this.gogo=setInterval(function(){handle.move()},17);
};
this.clear=function()
{
this.o.parentNode.removeChild(this.o);
clearInterval(this.gogo);
this.exist=false;
for(var i=0,j=this.star.length;i<j;i++)
{
this.star[i].shine(this.x,this.y);
}
}
}
function FireScene(n)
{
this.num=n;
this.SceneWidth=document.body.clientWidth;
this.SceneHeight=document.body.clientHeight;
this.step=Math.floor(this.SceneWidth/this.num);
this.firework=new Array();
for(var i=0;i<this.num;i++)
{
this.firework[i]=new Firework();
this.firework[i].setX(this.step*i);
this.firework[i].setY(this.SceneHeight-50);
}
this.fire=function()
{
for(var i=0,j=this.firework.length;i<j;i++)
{
this.firework[i].fire();
}
}
}
window.onload=function()
{
document.body.style.backgroundColor = "Black";
new FireScene(8).fire()
setInterval("new FireScene(8).fire()",2000);
}
</script>
</body>
</html>

点燃 [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐