📄 完整的游戏主界面.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>华容道模拟游戏</title>
<script>
var level=15;
var figs=new Array(49);//存放按钮的显示数字
var fg=false; //游戏是否已经开始
function deal(){
fg=true;
document.forms[0].elements[h_ind].style.visibility="visible";
document.forms[0].elements[level].style.visibility="hidden";
h_ind=level;
for(i=0;i<level;i++){
figs[i]=Math.floor(Math.random() * level)+1;
for(j=0;j<i;j++)
if(figs[i]==figs[j])
{i--; break;}
}
for(i=0;i<level;i++){
if(figs[i]<10) figs[i]=" "+figs[i]+" ";
else figs[i]=" "+figs[i];
document.forms[0].elements[i].value=figs[i];}
}
var h_ind=level;
function move(ind){
var slevel=Math.sqrt(level+1);
var right=((h_ind+1)%slevel==0)&&(ind==(h_ind-1)||ind==(h_ind-slevel)||ind==(h_ind+slevel));
var left=(h_ind%slevel==0)&&(ind==(h_ind+1)||ind==(h_ind-slevel)||ind==(h_ind+slevel));
var middle=h_ind%slevel!=0&&(h_ind+1)%slevel!=0&&(ind==(h_ind-1)||ind==(h_ind+1)||ind==(h_ind-slevel)||ind==(h_ind+slevel));
if(right||left||middle){
with(document.forms[0].elements[h_ind])
{ value=document.forms[0].elements[ind].value;
style.visibility="visible"; }
document.forms[0].elements[ind].style.visibility="hidden";
h_ind=ind;}
}
function suc(){
for(i=1;i<level+1;i++)
if(document.forms[0].elements[i-1].value!=i)
{alert("游戏还没完成!!");break;}
if(i==level+1)
alert("成功了!好样的!");
}
function redo(){
document.forms[0].elements[h_ind].style.visibility="visible";
for(i=0;i<level;i++)
document.forms[0].elements[i].value=figs[i];
document.forms[0].elements[level].style.visibility="hidden";
h_ind=level;
}
</script>
</head>
<body>
<form name="form1"><p>
<input type="button" value=" 1 " onClick="move(0);"><input type="button" value=" 2 " onClick="move(1);"><input type="button" value=" 3 " onClick="move(2);"><input type="button" value=" 4 " onClick="move(3);"><br>
<input type="button" value=" 5 " onClick="move(4);"><input type="button" value=" 6 " onClick="move(5);"><input type="button" value=" 7 " onClick="move(6);"><input type="button" value=" 8 " onClick="move(7);"><br>
<input type="button" value=" 9 " onClick="move(8);"><input type="button" value=" 10" onClick="move(9);"><input type="button" value=" 11" onClick="move(10);"><input type="button" value=" 12" onClick="move(11);"><br>
<input type="button" value=" 13" onClick="move(12);"><input type="button" value=" 14" onClick="move(13);"><input type="button" value=" 15" onClick="move(14);"><input type="button" value=" 16" style="visibility:hidden" onClick="move(15);"></p>
<p><input type="button" value=" 开始 " onClick="deal();"><br>
<input type="button" value=" 完成 " onClick="suc();"><br>
<input type="button" value=" 重玩 " onClick="redo();"></p>
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -