第九周总结

辛苦奋斗了好久的成果,终于把小游戏做出来了!尽管结果不理想 还是收获了许多

<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 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);
}
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++;
  currImg1=lastImg1=-1;
   if(count>=n)
   {
    clearInterval(myinter);
    mytime=mytime+((n*2)+40);
    alert("Next");
    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);
 }
 
  }
 
</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>
<br><br>
<br><br><br>
<br>
<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="mt"> </div>
      <p>
  
        <input name="按钮" type="button" id="b1" onClick="createTable();" value="开始"/>
    </p></td>
  </tr>
</table>
<br>
<p>&nbsp;</p>
</body>
</html>

posted on 2016-04-21 19:41  陪你看花火  阅读(106)  评论(0编辑  收藏  举报