📄 game2.html
字号:
<HTML>
<HEAD>
<script language="JavaScript">
<!-- Hiding
function initArray() {
this.length = initArray.arguments.length
for (var i = 0; i < this.length; i++)
this[i+1] = initArray.arguments[i]
}
var startpos = new initArray(9,9,9,9,9,0,0,0,9,0,0,0,9,0,0,0,9,9,9,9);
var pos = new initArray(9,9,9,9,9,0,0,0,9,0,0,0,9,0,0,0,9,9,9,9);
var nummoves= 0;
function random() {
today = new Date();
num = today.getTime();
num = Math.round(Math.abs(Math.sin (num)*1000000)) % 9;
return num;
}
function display(pos) {
parent.ga1.document.close();
parent.ga1.document.open();
parent.ga1.document.write("<form>");
parent.ga1.document.write("<input type='Button' value=' "+pos[6]+" ' onClick='parent.ga2.move(6)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[7]+" ' onClick='parent.ga2.move(7)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[8]+" ' onClick='parent.ga2.move(8)'> <br>");
parent.ga1.document.write("<input type='Button' value=' "+pos[10]+" ' onClick='parent.ga2.move(10)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[11]+" ' onClick='parent.ga2.move(11)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[12]+" ' onClick='parent.ga2.move(12)'><br>");
parent.ga1.document.write("<input type='Button' value=' "+pos[14]+" ' onClick='parent.ga2.move(14)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[15]+" ' onClick='parent.ga2.move(15)'>");
parent.ga1.document.write("<input type='Button' value=' "+pos[16]+" ' onClick='parent.ga2.move(16)'>");
parent.ga1.document.write("<p><br>移 动 次 数: "+nummoves+"次<br>");
win();
}
function move(num) {
// num is the number of the field the user clicked - not the image!
if (pos[num-4]==0) {
pos[num-4]= pos[num];
pos[num]= 0;
nummoves++;
}
else {if (pos[num-1]==0){
pos[num-1]= pos[num];
pos[num]= 0;
nummoves++;
}
else {if (pos[num+1]==0){
pos[num+1]= pos[num];
pos[num]= 0;
nummoves++;
}
else {if (pos[num+4]==0){
pos[num+4]= pos[num];
pos[num]= 0;
nummoves++;
}
//else illegal move => no move!
}
}
}
display(pos);
}
function win() {
if (pos[6]== 1 & pos[7]== 2 & pos[8]== 3 & pos[10]== 4 & pos[11]== 5
& pos[12]== 6 & pos[14]== 7 & pos[15]== 8 & pos[16]== 0) {
if (confirm('你 成 功 了! 还 想 再 玩 一 次 吗 ?')) newgame();
}
}
function newgame() {
var helparray= new initArray(0,0,0,0,0,0,0,0,0);
for (var i=1; i<9;i++) {
randomnum= random();
while (helparray[randomnum] || 0) {
randomnum= random();
}
helparray[randomnum]= i;
}
for (var i=1; i<21;i++) {
pos[i]= startpos[i];
}
for (var i=1; i<4; i++) {
for (var j=0; j<3; j++) {
pos[i+5+j*4]= helparray[i+3*j];
}
}
nummoves=0;
display(pos);
}
// -->
</script>
</HEAD>
<p>
<center>
<FORM NAME="buttonbar">
<INPUT TYPE="button" VALUE="开 始 !" onClick="newgame()"></FORM></center>
<h1>游 戏 规 则</h1><p>这 是 个 简 易 版 的<font color=red>华 容 道</font>游 戏。<br>您 必 须 将 上 面frame中 的 数 字 盘 重 新 排 列 成 和 这 个frame中 的 数 字 盘 一 模 一 样!数 字 "0" 表 示 空 格, 所 有 和 "0" 相邻 的 数 字 都 可 移 至 "0" 的 位 置 上。 只 要 您 在 想 移 动 的 数 字 上 按 一 下, 它 就 会 移 到 "0" 的 位 置。 试 试 看 吧!<p>
<form>
<input type="button" value=" 1 "><input type="button" value=" 2 "><input type="button" value=" 3 "><br>
<input type="button" value=" 4 "><input type="button" value=" 5 "><input type="button" value=" 6 "><br>
<input type="button" value=" 7 "><input type="button" value=" 8 "><input type="button" value=" 0 "><br>
</form><a href="javascript:history.back()" TARGET=_top>回 上 一 页</a>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -