打地鼠游戏,写到倒计时了,有没有人看我的博客哇!第一次发!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>打地鼠游戏</title>
<style type="text/css">
#d1{
width: 342px;
height: 500px;
/*border: solid;*/
margin: 0 auto;
}
/* td{
background: url("../img/00.jpg");
} */
</style>
<script type="text/javascript">
var ksb,ztb,tzb;
var sc,sj,jg;
var sc_Time;
var start_Time,game_Time;
var sTime;
var djs_span;
window.onload = function(){
//动态生成表格
var t = document.createElement('table');
t.style.width = 350;
t.style.border = 1;
for(var i = 0;i<5;i++){
var tr = document.createElement("tr");
for(var j =0;j < 5;j++){
var td = document.createElement("td");
var image = document.createElement("img");
image.src = "../img/00.jpg";
td.appendChild(image);
tr.appendChild(td);
}
t.appendChild(tr);
}
document.getElementById('game').appendChild(t);
//倒计时
ksb = document.getElementById("ksb");
sc = document.getElementById("sc");
djs_span = document.getElementById("djs");
sj = document.getElementById("sj");
jg = document.getElementById("jg");
ksb.onclick = function() {
sc_Time = parseInt(sc.value);
start_Time = new Date();//游戏开始时间
djs();
}
function djs() {
var game_Time = new Date();//游戏正在运行的时间
sTime = sc_Time*60-parseInt((game_Time-start_Time)/1000);
djs_span.innerHTML = sTime;
setTimeout(djs,1000);
jz();
if(sTime<1){
djs_span.innerHTML = "";
}
}
function jz() {
sj.disabled = true;
jg.disabled = true;
sc.disabled = true;
}
// 游戏机制
function fx1(){
var obj = document.getElementsByTagName('tr');
var random = parseInt(Math.random()*obj.length)+1;
alert(random);
}
}
</script>
</head>
<body>
<div id="d1">
地鼠停留时间:<input type="text" id="sj" size="5" value="1">秒<br>
地鼠出现间隔:<input type="text" id="jg" size="5" value="1">秒<br>
游戏时长:<input type="text" id="sc" size="5" value="1">分钟<br>
游戏倒计时:<span id="djs"></span>秒<br>
游戏得分:<span id="df"></span><br>
<input type="button" id="ksb" value="开始游戏">
<input type="button" id="ztb" value="暂停游戏">
<input type="button" id="tzb" value="停止游戏">
<div>
<hr>
<div id="game">
<!-- 游戏区域 -->
</div>
</body>
</html>