📄 html+javascript俄罗斯方块.html
字号:
if (isNaN(table[i*16+j])||i==21) break;
c+=table[i*16+j];
}
if(c==12) //当一行填满后,执行消行函数,并记录数据
{
DelLine(i);
i++;
d++;
}
}
if (d>0)
sco.innerText=parseInt(sco.innerText)+d*d*36;
}
//游戏结束判断程序
function Lucifer()
{
for(var i=2;i<14;i++)
{
if (table[16+i]==1) return true;
}
return false;
}
//游戏结束执行程序
function GameOver()
{
gameover=1;
clearInterval(gameInterval);
block_div.innerHTML="";
for (i=0;i<21;i++)
{
for (j=2;j<14;j++)
{
setTimeout("table_tbl.rows(" + i + ").cells(" + j + ").style.background = colors[Math.round(Math.random()*7)];",16*i*j);
}
}
nblock_div.innerHTML = "你太菜了<br><br><font size=2> <input type=button onclick='javascript:location.href=location.href' value='再玩一次'></font>";
}
//键盘控制以及方块移动判断
function document_onkeydown()
{
if (gameover==1) return;
with (block_div.style)
{
curX = pixelLeft;
curY = pixelTop;
switch (event.keyCode)
{
case 37: //左移及判断
if(pause==1||gamestart==0)
{break;}
if (CanMove(curX-n_IncStep,curY,arr_curBlock))
pixelLeft-=n_IncStep;
break;
case 38: //变形及判断
if(pause==1||gamestart==0)
{break;}
Change(1);
break;
case 39: //右移及判断
if(pause==1||gamestart==0)
{break;}
if (CanMove(curX+n_IncStep,curY,arr_curBlock))
pixelLeft+=n_IncStep;
break;
case 40: //下落及判断
if(pause==1||gamestart==0)
{break;}
if (CanMove(curX,curY+n_IncStep,arr_curBlock))
{
pixelTop+=n_IncStep;
}
else
{
SaveBlock();
DelLines();
if (Lucifer())
{
GameOver();
return;
}
sco.innerText=parseInt(sco.innerText)+2;
NewBlock();
}
break;
case 32:
if (pause==0)
{
if (gameInterval=="")
{break;}
clearInterval(gameInterval);
pause=1;
}
else
{
gameInterval=window.setInterval("Handle_Interval()",(maxspeed-speed+1)*60);
pause=0;
}
break;
case 90:
if(pause==1||gamestart==0)
{break;}
Change(1);
break;
case 88:
if(pause==1||gamestart==0)
{break;}
Change(-1);
break;
default:
}
}
}
//控制函数,方块间距检查,另外进行游戏执行判断,比如判断是否需要加速,游戏结束与否,等等。
function Handle_Interval()
{
curX = block_div.style.pixelLeft;
curY = block_div.style.pixelTop;
if (CanMove(curX,curY+n_IncStep,arr_curBlock))
{
block_div.style.pixelTop+=n_IncStep;
}
else
{
SaveBlock();
DelLines();
if (Lucifer())
{
GameOver();
return;
}
sco.innerText=parseInt(sco.innerText)+2
NewBlock();
}
if (killedlines>=clr_per_line) //判断所消行的数量是否达到“标准”,这里clr_per_line初始化的量为18,故当消去18行后,速度变量speed自加1.
{
killedlines-=clr_per_line;
if (speed<maxspeed)
speed++;
else
speed=maxspeed;
spd.innerText=speed;
clearInterval(gameInterval);
gameInterval=window.setInterval("Handle_Interval()",(maxspeed-speed+1)*60);
}
}
//-->
</script>
<script event=onkeydown for=document language=javascript>
<!--
if (document.all)
document_onkeydown()
//-->
</script>
<div id=block_div style="LEFT: 60px; TOP: 0px">
<table border=0 cellpadding=0 cellspacing=0 id=block_tbl>
<script>
if (document.all)
{
for (var i=0;i<4;i++)
{
document.write("<tr>");
for (var j=0;j<4;j++)
{
document.write("<td style=\"border:1 solid black;\"></td>");
}
document.write("</tr>");
}
}
</script>
<tbody></tbody>
</table>
</div>
<div id=nblock_div>
<table border=0 cellpadding=0 cellspacing=0 id=nblock_tbl>
<script>
if (document.all)
{
for (var i=0;i<4;i++)
{
document.write("<tr>");
for (var j=0;j<4;j++)
{
document.write("<td style=\"height:40;width:40;border:1 outset black;\"></td>");
}
document.write("</tr>");
}
}
</script>
<tbody></tbody>
</table>
</div>
<div id=table_div>
<table border=0 cellpadding=0 cellspacing=0 id=table_tbl>
<script>
if (document.all)
{
for (var i=0;i<22;i++)
{
document.write("<tr>");
for (var j=0;j<16;j++)
{
var d2 = i * 16 + j;
if (table[d2]==1)
document.write("<td bgcolor=navy></td>");
else
document.write("<td style=\"background:black;\"></td>");
}
document.write("</tr>");
}
}
</script>
<tbody></tbody>
</table>
</div>
<!--对于界面说明的描述部分,以及一些提示性信息-->
<div id=title_div noWrap>
<pre>
起始速度:( 请输入个位数字"1-9" )
<input id=speedin size=11 value=1>
<button id=but onClick=begintet()>开始</button> <input type="button" value="重来" onclick="if(confirm('有种点“取消”继续!')) location.reload();" /> </pre>
<br>
<pre><font color=999999>下一块:</font>
说明:<br> <br>
<font color=white> ↑ :改变形状 ← :向左移动<br>
→ :向右移动 ↓ :向下移动<br>
<br>
空格键:暂停/继续</font> <br>
<br>
</div> </pre>
<div id=infobar_div>
<table border=1 bordercolor=#212121 cellpadding=0 cellspacing=0>
<tbody>
<tr align=middle>
<td style="COLOR: white; FONT: 12px system; WIDTH: 56px"><font
size=2>速度</font>:</td>
<td id=spd style="COLOR: red; FONT: 12px system">1</td>
<td style="COLOR: white; FONT: 12px system; WIDTH: 86px">总分:</td>
<td id=sco style="COLOR: red; FONT: 12px system">0</td>
<td style="COLOR: white; FONT: 12px system; WIDTH: 96px">成绩:</td>
<td id=cll
style="COLOR: red; FONT: 12px system">0</td>
</tr>
</tbody>
</table>
</div>
<!-主函数调用->
<div id=infobar2_div></div>
<script id=MainSection language=javascript>
<!--
if (document.all)
{
ncid = Math.round(Math.random()*(colors.length-1));
bid = Math.round(Math.random()*(blocks.length-1));
nextBlock = blocks[bid];
NewBlock();
}
function begintet()
{
gamestart=1;
document.all.speedin.disabled=true;
document.all.but.disabled=true;
speed=parseInt(document.all.speedin.value);
if (isNaN(speed)||speed==null||speed>maxspeed||speed<1) speed=1;
spd.innerText=speed;
gameInterval=window.setInterval("Handle_Interval()",(maxspeed-speed+1)*60);
}
//-->
</script>
<div id='dh' style="position:absolute; left:-800px; top:-800px; width:0px; height:0px; z-index:1">
<input type=button value='-' name='goppp' onClick='Javascript:window.close();' accesskey='q'>
</div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -