周总结<2>

时间:2022-10-03 08:38:48

本打算在这周日写周总结的,但由于事情太多,还要组织团日活动,所以没时间写。不过上周主要是一些书本上的学习,但是在周日的时候完成了一款小游戏还是比较有成就感的,但是主要是因为html的考试才去做的。

代码如下:

<!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>game</title>

<script type="text/javascript" >

var myarr=new Array();

var curr=-1;

var last=-1;

var isused=new Array();

var count=0;

var n;

var sum=0;

var ts=0;

var row=-1;

var col=-1;

var time=60;

function f(row,col)

{

function mysort()//取随机数

{

return Math.random()>.5;

}

n=(row*col)/2;

for(var k=0;k<(2*n);k++)

{

isused[k]=false;

}

for(var k=0;k<n;k++)

{

myarr[k]=Math.ceil(Math.random()*17);

//myarr[k]=( Math.round( Math.random()*5 )+1);

myarr[k+n]=myarr[k];

}

myarr.sort(mysort);

var str;

str="<table border='0' width='400' height='400'  align='center' >";

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/image0.gif'/>"

str+="</td>";

}

str+="</tr>";

}

str+="</table>";

document.getElementById("w").innerHTML=str;

}

function sss()

{

if(row<0&&col<0){

row=3;

col=4;

}

onre();

}

function judge(e)

{

//alert(myarr[e]);

if(isused[e])

return;

isused[e]=true;

last=curr;

curr=e;

var temp=document.getElementById("img_"+e);

temp.src="photo/image"+myarr[e]+".gif";

if(last>=0)

{

if(myarr[curr]==myarr[last])

{

//alert("匹配");

count++;

curr=last=-1;

if(count==n)

{

ts=1;

sum++;

if(sum==5){

alert("通关成功");

document.getElementById("11").innerHTML="";

docoment.write("you are winner");

return 0;

}

alert("next");

count=0;

time-=5;

row++;

col++;

sss();

}

}

else

{

var temp=document.getElementById("img_"+last);

temp.src="photo/image0.gif";

isused[last]=false;

}

}

}

function onre()

{

var myTime=time;

function countDown()

{

var minute=Math.floor(myTime/60);

var second=myTime%60;

var s=String(100+minute).substr(1,2) +":"+String(100+second).substr(1,2);

document.getElementById("mt").innerHTML=s;

myTime--;

if(ts){

ts=0;

return ;

}

if(myTime>0)

{

setTimeout(countDown,1000);

//judge(e);

}

else

{

document.getElementById("mt").innerHTML="";

document.getElementById("w").innerHTML="";

alert("over");

var x=sum*20;

docoment.write("您的总分是:");

docoment.write(x);

sss();

}

}

setTimeout(countDown,1000);

f(row,col);

}

</script>

</head>

<style>

body{background-image:url(back1.jpg);}

</style>

<body  id="11">

<div id="w"  align="center" >game</div>

<div id="mt"  align="center" >time</div>

<input type="button"  value="begin" onclick="sss()"  align="center"  />

<EMBED src='music.mp3' width='0' height='0' type=audio/mpeg loop="1" autostart="1" volume="0"></EMBED>

</body>

</html>