|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
<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 myArray=new Array(); |
|
var row=3; |
|
var col=4; |
|
var currImgNo=-1; |
|
var lastImgNo=-1; |
|
var count=0; |
|
var n; |
|
var isUsed=new Array(); |
|
var timeCount=100; |
|
var myInterval; |
|
|
|
function mySort() |
|
{ |
|
return Math.random()>.5; |
|
} |
|
function init(row,col) |
|
{ |
|
var n= (row*col)/2; |
|
for(var k=0;k< (2*n);k++) |
|
{ |
|
isUsed[k]=false; |
|
|
|
|
|
} |
|
for(var k=0;k<n;k++) |
|
{ |
|
myArray[k]=Math.ceil( Math.random() *10); |
|
myArray[k+n]=myArray[k]; |
|
} |
|
myArray.sort(mySort); |
|
var str='<table border="1" width="300" height="300">'; |
|
for(var i=1;i<=row;i++) |
|
{ |
|
str +="<tr>"; |
|
for(var j=0;j<col;j++) |
|
{ |
|
//str +="<td onclick='judge("+ ( (i-1)*col+j) +");'>" + myArray[ ((i-1)*col+j) ] +"</td>"; |
|
str+="<td onclick='judge("+ ( (i-1)*col+j) +");'>" |
|
str+= '<img id="img_'+( (i-1)*col+j) +'" src="photo/image0.gif"/>' |
|
str+="</td>"; |
|
} |
|
str +="</tr>"; |
|
} |
|
str+='</table>'; |
|
document.getElementById("hl").innerHTML=str; |
|
//myInterval=setInterval("runTime()",500); |
|
myInterval=setInterval(runTime,500); |
|
} |
|
function runTime() |
|
{ |
|
var minute =parseInt(timeCount/60); |
|
var second =timeCount%60; |
|
var stcm=document.getElementById("ayTime").innerHTML=minute+":"+second; |
|
timeCount--; |
|
if(timeCount<0) |
|
{ |
|
alert("时间到"); |
|
clearInterval(myInterval); |
|
} |
|
|
|
} |
|
function onRe() |
|
{ |
|
init(row,col); |
|
row++//document.getElementById("t1").value; |
|
col++//document.getElementById("t2").value; |
|
// init(row,col); |
|
document.getElementById("next").value="next"; |
|
|
|
} |
|
function judge(temp) |
|
{ |
|
if(isUsed[temp]) return; |
|
isUsed[temp]=true; |
|
|
|
lastImgNo=currImgNo; |
|
currImgNo=temp; |
|
|
|
|
|
var currImg=document.getElementById("img_"+temp); |
|
currImg.src="photo/image"+myArray[temp]+".gif"; |
|
if(currImgNo>=0 && lastImgNo>=0) |
|
{ |
|
|
|
if(myArray[currImgNo]==myArray[lastImgNo]) |
|
{ |
|
//alert("成功"); |
|
|
|
|
|
//count++; |
|
currImgNo=lastImgNo=-1; |
|
if(count>=n) |
|
{ |
|
alert("游戏结束,进入下一关!"); |
|
onRe(); |
|
|
|
} |
|
|
|
|
|
} |
|
else |
|
{ |
|
var lastImg=document.getElementById("img_"+lastImgNo); |
|
lastImg.src="photo/image0.gif"; |
|
isUsed[lastImgNo]=false; |
|
} |
|
|
|
} |
|
} |
|
|
|
|
|
</script> |
|
</head> |
|
|
|
<body> |
|
<html> |
|
<body> |
|
<div id="ayTime"> 点击</div> |
|
<div id="hl"> 开始游戏</div> |
|
|
|
<input id="next" type="button" width="20" value="开始游戏" onclick="onRe();" /> |
|
</body> |
|
</html> |
|
|
|
|
|
|
|
|