<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
// var ran = parseInt(Math.random()*25);// 0 -- 24
// document.write(ran);
var img;
var imgs;
window.onload = function(){
//游戏开始
document.getElementById("btn").onclick = function(){
// var imgs = document.getElementsByTagName("img");
//获取所有图片对象的数组
imgs = document.images;
show();
}
document.getElementById("yc").onclick = function(){
img.src = "img/00.jpg";
}
}
//地鼠出现方法
function show(){
//获取随机的一张图片的下标
var i = parseInt(Math.random()*imgs.length);
//地鼠随机出现
img = imgs[i];
img.src = "img/01.jpg";
setTimeout("show()",1000);
}
//打击地鼠方法
function play(obj){
//获取图片名称
var str = obj.src;
var s = str.split("/");
var name = s[s.length-1].charAt(1);
if(name == 1){
obj.src = "img/02.jpg";
}
// document.getElementById("str").innerHTML = s[s.length-1].charAt(1);
// var mess = "";
// for (var i = 0 ; i < s.length ; i++) {
// mess += s[i]+"<br>";
// }
// document.getElementById("str").innerHTML = mess;
}
</script>
</head>
<body>
<button id="btn">开始</button>
<button id="yc">隐藏</button>
<!--游戏区域-->
<table border="1px">
<tr>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
</tr>
<tr>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
</tr>
<tr>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
</tr>
<tr>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
</tr>
<tr>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
<td><img src="img/00.jpg" onclick="play(this)" /></td>
</tr>
</table>
<span id="str"></span>
</body>
</html>
地鼠出现
最新推荐文章于 2020-02-18 17:10:31 发布