玩法,点击某一格,该格及该格上下左右都颜色反转,如果最后全部反成绿色,则过关!
<html>
<head>
<style type=text/css>
<!--
body{
margin:0;
podding:0;
}
#div_main{
left:0;
top:0;
width:150px;
height:150px;
position:absolute;
background-color:#0066ff;
}
#div_control{
left:0;
top:170;
width:150px;
height:150px;
position:absolute;
background-color:#0066ff;
}
-->
</style>
<script language=javascript>
var pazuru=new Array();;
function checkfinished()
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(pazuru[i][j]==0)
return false;
}
}
return true;
}
function exchange(i,j)
{
if(pazuru[i][j]==0)
pazuru[i][j]=1;
else
pazuru[i][j]=0;
if(i>0)
{
if(pazuru[i-1][j]==0)
pazuru[i-1][j]=1;
else
pazuru[i-1][j]=0;
}
if(i<4)
{
if(pazuru[i+1][j]==0)
pazuru[i+1][j]=1;
else
pazuru[i+1][j]=0;
}
if(j>0)
{
if(pazuru[i][j-1]==0)
pazuru[i][j-1]=1;
else
pazuru[i][j-1]=0;
}
if(j<4)
{
if(pazuru[i][j+1]==0)
pazuru[i][j+1]=1;
else
pazuru[i][j+1]=0;
}
}
function showpoint()
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
temp="div_x"+i+"y"+j;
var pointvalue=document.getElementById(temp);
if(pazuru[i][j]==1)
{
pointvalue.style.background="#00ff00";
}
else
pointvalue.style.background="#ff9900"; }
}
}
function init()
{
for(i=0;i<5;i++)
{
pazuru[i]=new Array(0,0,0,0,0)
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
var div=document.createElement('div');
div.id="div_x"+i+"y"+j;
div.onclick=play;
with(div.style)
{
left=i*30;
top=j*30;
width=28;
height=28;
position="absolute";
background="#ff9900";
margin=1;
}
document.all.div_main.insertAdjacentElement('beforeEnd',div);
}
}
}
function play()
{
var gameover;
var i=parseInt(event.x/30);
var j=parseInt(event.y/30);
exchange(i,j);
showpoint();
gameover=checkfinished();
if(gameover)
{
alert("Finished!");
init();
}
}
</script>
</head>
<body onload="init();">
<div id=div_main>
</div>
</body>
</html>
[此贴子已经被作者于2007-3-6 14:11:08编辑过]