注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

浩瀚星云

上善若水 厚德载物<学习版>

 
 
 

日志

 
 

堆积游戏  

2008-05-03 10:28:36|  分类: ASP(过时) |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

<html>
<head>
<title>网页特效|Linkweb.cn/Js|---堆积游戏</title>
<style type="text/css">
<!--
body {  font-family: "宋体"; font-size: 9pt; margin-top: 0px; margin-left: 0px; margin-right: 0px}
A { COLOR: black; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: none }
 A:hover { COLOR: red; FONT-SIZE: 9pt; FONT-WEIGHT: 400; TEXT-DECORATION: underline }
a:active     { font: 9pt "宋体"; cursor: hand; color: #FF0033 }

-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<SCRIPT LANGUAGE="JavaScript">

<!-- Begin
var MAXHEIGHT = 8;
var ndisk;
var timer = null;
var mvfrom = new Array(255);
var mvto = new Array(255);
var mv, imv;
var tower = new Array(3);
var h = new Array(3);
var spc = "        ";
var dname = new Array(
"|",
"111",
"22222",
"3333333",
"444444444",
"55555555555",
"6666666666666",
"777777777777777",
"88888888888888888");

function init() {
if (!timer) {
s = document.formHanoi.disk.options[document.formHanoi.disk.selectedIndex].value;
if (s == "random") {
now = new Date();
ndisk = parseInt(now.getTime() / 1000) % 8 + 1;
delete now;
}
else ndisk = s;
mv = 0;
hanoi(0, 2, 1, ndisk);
for (i = 0; i < 3; i++)
tower[i] = new Array(MAXHEIGHT);
for (i = 0; i < ndisk; i++)
tower[0][i] = ndisk - i;
h[0] = ndisk;
h[1] = h[2] = 0;
imv = 0;
document.formHanoi.display.value = gentower();
timer = window.setTimeout("gennexttower()", document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
   }
}
function stop() {
if (timer) {
window.clearTimeout(timer);
timer = null;
   }
}
function hanoi(from,to,buf,nmv) {
if (nmv > 1) {
hanoi(from, buf, to, nmv - 1);
mvfrom[mv] = from;
mvto[mv++] = to;
hanoi(buf, to, from, nmv - 1);
}
else {
mvfrom[mv] = from;
mvto[mv++] = to;
   }
}
function gennexttower() {
tower[mvto[imv]][h[mvto[imv]]++] = tower[mvfrom[imv]][--h[mvfrom[imv]]];
document.formHanoi.display.value = gentower();
if (++imv < mv)
timer = window.setTimeout("gennexttower()", document.formHanoi.delay.options[document.formHanoi.delay.selectedIndex].value);
else {
for (i = 0; i < 3; i++)
delete tower[i];
timer = null;
    }
}
function gentower() {
s = " \n";
for (i = MAXHEIGHT - 1; i >= 0; i--) {
for (j = 0; j < tower.length; j++) {
len = i < h[j] ? tower[j][i] : 0;
width = MAXHEIGHT - len;
s += " " + spc.substring(0, width) + dname[len] + spc.substring(0, width);
}
s += "\n";
}
return s+"=======================================================";
}
//  End -->
</script>
</head>
<body>
<br>
<br>
<center><font color=red face="隶书" size=6>堆积游戏</font></center>
<br>
<br><center>
<table border=0 bordercolor=blue borderlight=green style="border-collapse: collapse" cellpadding="0" cellspacing="0">
<tr><td align=center><font size=5 color=red face="Arial, Helvetica, sans-serif"><strong>请点击按钮!</strong></font></td></tr><tr><td align=center><form name=formHanoi>
<textarea name=display rows=10 cols=56></textarea><br>
<table border=0 cellspacing=10 cellpadding=0>
<tr>
<td>堆积层数</td>
<td><select name=disk>
<option selected value=random>层数
<option value=1>1
<option value=2>2
<option value=3>3
<option value=4>4
<option value=5>5
<option value=6>6
<option value=7>7
<option value=8>8
</select></td>
</tr>
<tr>
<td>延迟时间</td>
<td><select name=delay>
<option value=100>100 milliseconds
<option value=200>200 milliseconds
<option value=300>300 milliseconds
<option value=400>400 milliseconds
<option selected value=500>500 milliseconds
<option value=600>600 milliseconds
<option value=700>700 milliseconds
<option value=800>800 milliseconds
<option value=900>900 milliseconds
<option value=1000>1000 milliseconds
</select></td>
</tr>
</table>
<input type=button value="Start" onClick="init();">
<input type=button value="Stop" onClick="stop();">
</form></td></tr>
</table></center>
<br>
<br>

<br>
<br>
</body>
</html>

  评论这张
 
阅读(48)| 评论(0)
推荐 转载

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2017