<!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>144105213打地鼠</title>
<style type="text/css">
#bb
{
width: 960px;
margin: 0 auto;
text-align: center;
}
table
{
margin: 0 auto;
}
td
{
width: 80px;
height: 80px;
background-color:#0F9;
}
</style>
<script language="JavaScript">
var s = new Array(),
playing = false,
fs = 0,
beat = 0,
mzl = 0,
knock = 0,
countDown = 30,
interId = null,
timeId = null;
var no;
function yxjs(){
timeStop();
playing = false;
sx();
alert("游戏结束!\n你获得的分数为:"+fs+"\n命中率为:"+mzl);
mzl = 0;
fs = 0;
knock = 0;
beat = 0;
countDown = 30;
}
function timeShow()
{
document.form1.remtime.value = countDown;
if(countDown == 0)
{
yxjs();
return;
}
else
{
countDown = countDown-1;
timeId = setTimeout("timeShow()",1000);
}
}
function timeStop()
{
clearInterval(interId);
clearTimeout(timeId);
}
function show()
{
if(playing)
{
var current = Math.floor(Math.random()*16);
document.getElementById("s["+current+"]").innerHTML = '<img src="01.png">';
setTimeout("document.getElementById('s["+current+"]').innerHTML=''",1000);
}
}
function sx()
{
for(var i=0;i<=15;i++)
{
document.getElementById("s["+i+"]").innerHTML="";
}
}
function dj(id)
{
if(playing==false)
{
return;
}
else
{
beat +=1;
if(document.getElementById("s["+id+"]").innerHTML!="")
{
fs += 1;
knock +=1;
mzl = parseInt(knock/beat*100);
document.form1.mzl.value = mzl;
document.form1.fs.value = fs;
document.getElementById("s["+id+"]").innerHTML="";
}
else
{
fs += -1;
mzl = parseInt(knock/beat*100);
document.form1.mzl.value = mzl;
document.form1.fs.value = fs;
}
}
}
function yxks(){
playing = true;
interId = setInterval("show()",1000);
document.form1.fs.value = fs;
document.form1.mzl.value = mzl;
timeShow();
}
</script>
</head>
<body>
<div id="bb">
<input type="button" value="开始游戏" onclick="yxks()">
<input type="button" value="结束游戏" onclick="yxjs()">
<form name="form1">
<label>分数:</label>
<input type="text" name="fs" size="5">
<label>命中率:</label>
<input type="text" name="mzl" size="10">
<label>倒计时:</label>
<input type="text" name="remtime" size="5">
</form><br>
<table>
<tr>
<td id="s[0]" onclick="dj(0)"></td>
<td id="s[1]" onclick="dj(1)"></td>
<td id="s[2]" onclick="dj(2)"></td>
<td id="s[3]" onclick="dj(3)"></td>
</tr>
<tr>
<td id="s[4]" onclick="dj(4)"></td>
<td id="s[5]" onclick="dj(5)"></td>
<td id="s[6]" onclick="dj(6)"></td>
<td id="s[7]" onclick="dj(7)"></td>
</tr>
<tr>
<td id="s[8]" onclick="dj(8)"></td>
<td id="s[9]" onclick="dj(9)"></td>
<td id="s[10]" onclick="dj(10)"></td>
<td id="s[11]" onclick="dj(11)"></td>
</tr>
<tr>
<td id="s[12]" onclick="dj(12)"></td>
<td id="s[13]" onclick="dj(13)"></td>
<td id="s[14]" onclick="dj(14)"></td>
<td id="s[15]" onclick="dj(15)"></td>
</tr>
</table>
</div>
<br><br><br><hr>
</body>
</html>