标签:
周数 | 专业目标学习 | 专业学习时间 | 博客发表量 | 人文方面的学习 | 知识技能总结 |
9 | 数据结构与算法,HTML,计算机网络基础 | 平均5小时/天 | 9 | 四级词汇 | 这周期中考,HTML考试内容是写小游戏,为了写它,我熬夜到了凌晨3点,尽我所能做了... |
<!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" background=""> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> | |
<style type="text/css"> | |
html{text-align:center;} | |
body{width:778px;margin:0 auto;text-align:left;} | |
img{border:none;} | |
</style> | |
<title>翻牌小游戏</title> | |
<div id="mm"></div> | |
<script type="text/javascript"> | |
var sum=0; | |
var myarr=new Array(); | |
var lastImgNo=-1; | |
var currImgNo=-1; | |
var isused=new Array(); | |
var count=0; | |
var n; | |
var time=0; | |
function DownTime(i)//计时器 | |
{ | |
document.getElementById("countT").value=time; | |
time=time+1; | |
setTimeout("DownTime()",1000); | |
if(i==2) | |
{time=time-1; | |
alert("您用时共:"+""+time+"s"); | |
return ; | |
} | |
} | |
function pauseclock() | |
{ | |
DownTime(2); | |
} | |
function mySort() | |
{ | |
return Math.random()>.5; | |
} | |
function init(row, col) | |
{ | |
n=(row*col)/2; | |
for(k=0;k<(2*n);k++) | |
{ | |
isused[k]=false; | |
} | |
for(var k=0;k<n;k++) | |
{ | |
myarr[k]=Math.ceil(Math.random()*20); | |
myarr[k+n]=myarr[k]; | |
} | |
var str=‘<table name="myT" border="1" width="240" height="240">‘; | |
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/img0.jpg‘/>" | |
str+="</td>"; | |
} | |
str+="</tr>"; | |
} | |
str+= "</table>" | |
str+="计时器:<input style=‘color:blue;width:50px;background:write;‘ type=‘text‘ id=‘countT‘ value=‘‘>" | |
//0--12 | |
myarr.sort(mySort); | |
// i=1 j=1---3 1 2 3 (i-1)*3+j | |
//i=2 4 5 6 | |
//document.write(str); | |
document.getElementById("mt").innerHTML=str; | |
//document.getElementById("mt").text=myArray; | |
} | |
function createTable(row,col) | |
{ | |
count=0; | |
init(row,col); | |
} | |
function judge(e) | |
{ | |
if(isused[e]) | |
return ; | |
lastImgNo=currImgNo; | |
currImgNo=e; | |
var temp=document.getElementById("img_"+e); | |
temp.src="photo/img"+myarr[e]+".jpg"; | |
if(lastImgNo>=0) | |
{ | |
if(myarr[currImgNo]==myarr[lastImgNo]) | |
{ | |
count++; | |
lastImgNo=currImgNo=-1; | |
isused[e]=true; | |
if(count==n) | |
{ | |
alert("祝贺你哦,闯关成功!"); | |
createTable(3,4); | |
} | |
} | |
else | |
{ | |
var temp=document.getElementById("img_"+lastImgNo); | |
temp.src="photo/img0.jpg"; | |
isused[lastImgNo]=false; | |
} | |
} | |
} | |
</script> | |
</head> | |
<body style="background-image:url(photo/img100.jpg)"> | |
<h1> <div id="mt">游戏规则:点击开始游戏,找出两两相同的图片,完成一关可点击确定,进入下一关,最后可计算所用的时间~~</div></h1> | |
<input type="button" value="开始游戏" style=‘background:url(photo/img22.jpg);font-size:45px;font-family: "华文彩云"; border-style:none; | |
width:250px; height:200px; background-repeat:no-repeat;‘ onClick="createTable(2,3);DownTime(1)"/> | |
<input name="s" type="button" value="终止计时" onClick="pauseclock()"> | |
</body> | |
</html> | |
标签:
原文地址:http://www.cnblogs.com/mjs123/p/5419480.html