周总结

总算把小游戏搞定了。虽然评分还是及格,但是毕竟是自己的处女作嘻嘻。  

<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>火影忍者对对碰</title>

<script type="text/javascript">
var currImg1=-1;
var lastImg1=-1;
var count=0;
var n;
var isused=new Array();
var row=3;
var col=4;
//时钟变量
var mytime=30;
var minute;
var secound;
var str1;
var count;
var myinter;
//积分器
var jifen1;
var score=0;

var myArray=new Array(34);


function mySort()
{
return Math.random()>.5;
}

function init(row, col)
{
n=(row*col)/2;
for(var k=0;k<(n*2);k++)
{
isused[k]=false;
}
for(var k=0;k<n;k++)
{
myArray[k]=( Math.round( Math.random()*9)+1);
myArray[k+n]=myArray[k];
}
myArray.sort(mySort);


var str='<table name="myT" border="1" width="300" height="300" bgcolor="#FFFFFF" bordercolor="#9F9"border="1"cellspacing="1" cellpadding="1" >';
for(var i=1;i<=row;i++)
{
str+="<tr>";
for(var j=0;j<col;j++)
{
str+="<td onclick='judge("+ ((i-1)*col +j )+");'>"
str +="<img id='img_"+ ((i-1)*col +j )+"' src='photo/image0.jpg'/>"
str+="</td>";
}
str+="</tr>";
}
str+= "</table>"
document.getElementById("mt").innerHTML=str;

}
function createTable()
{
init(row,col);
row++;
col++;
myinter=setInterval(setTime,1000);
b1.style.display="none";
}
function judge(temp)
{
if (isused[temp]) return;
isused[temp]=true;
lastImg1=currImg1;
currImg1=temp;



var currImg=document.getElementById("img_"+temp);
currImg.src="photo/image"+myArray[temp]+".jpg";
//alert(myArray[temp]);
if(currImg1>=0 &&lastImg1>=0)
{

if(myArray[currImg1]==myArray[lastImg1])
{
count++;
score++;
jifen1=score*20;
document.getElementById("mt3").innerHTML=jifen1;
currImg1=lastImg1=-1;
if(count>=n)
{
clearInterval(myinter);
mytime=mytime+((n*2)+40);
alert("恭喜进入下一关");
createTable();
count=0;


}
}
else
{

var lastImg=document.getElementById("img_"+lastImg1);
lastImg.src="photo/image0.jpg";
isused[lastImg1]=false;
}

}
}

function setTime()//计时器
{

minute=Math.floor(mytime/60);
secoud=mytime%60;
str1=String(minute+100).substr(1,2)+":"+String(secoud+100).substr(1,2);
document.getElementById("mt2").innerHTML=str1;
mytime--;
if(mytime<0)
{
clearInterval(myinter);
alert("游戏结束");


}

}

</script>
<style type="text/css">
<!--
body {
background-image: url(photo/bg1.jpg);
background-repeat: repeat;
}
body,td,th {
color: #06F;
font-size: 24px;
font-weight: bold;
}
-->
</style></head>

<body>
<br>
<h2 align="center">火影忍者记忆王</h2>
<h2 align="center">威哥出品</h2>
<div id="mt4" align="center"></div>
<div id="mt2" align="center">
<p>倒计时</p>
</div>
<table width="100%" border="0" align="center">
<tr>
<td align="center"><br>
<div id="mt3" align="center">0</div>
<div id="mt"> </div>
<p>

<input name="按钮" type="button" id="b1" onClick="createTable();" value="开始"/>
</p></td>
</tr>
</table>
<br>
<p>&nbsp;</p>
</body>
</html>

posted @ 2016-04-21 19:34  行走的车站  阅读(127)  评论(0编辑  收藏  举报