window.event.keyCode==83)
gameStart();
}
function gameStart() {
Message.style.visibility = "hidden";
score=0; line=0; level=1; speed=1500;
Tetris.clear();
Preview.clear();
show();
Block = new block(Tetris,Shapes[Math.round(Math.random()*6)]);
NextBlock = new block(Preview,Shapes[Math.round(Math.random()*6)]);
Block.draw();
NextBlock.draw();
handle = window.setTimeout('down()',speed);
document.body.onkeypress = keyPlay;
}
function gameOver() {
handle = NaN;
document.body.onkeypress = keyWait;
Message.innerHTML = '俄罗斯方块 v1.0beta<br><br><font size=5>游戏结束!</font><br><br>按 S 键重新开始,<br>J,K,L键控制方块移动,<br>按 I 键控制方块旋转<br><br>2001-10-19 by 黄砾(stone)<br>http://bbs.online.jx.cn';
Message.style.visibility = 'visible';
}
function show() {
Show.innerHTML = '<P><b>Hiscore</b><br>' + Hiscore + '</P><P><b>Score</b><br>' + score + '</P><P><b>Level</b><br>' + level + '</P><P><b>Line</b><br>' + line + '</P><P> </P><P> </P><P> </P>';
}
function down() {
Block.clear();
if (!Block.down()) {
Block.draw();
var eraseLine = Tetris.eraseLine();
line += eraseLine;
score+= 50*((1<<eraseLine)-1);
if (score>Hiscore)
Hiscore=score;
if ((score>>9)>level) {
level++;
speed=Math.round(speed/1.3);
if (speed<80)
speed=80;
}
NextBlock.clear();
Block = NextBlock;
Block.setObj(Tetris);
show();
if (!Block.check()) {
gameOver();
return;
}
NextBlock = new block(Preview,Shapes[Math.round(Math.random()*6)]);
NextBlock.draw();
}
Block.draw();
handle = window.setTimeout("down()",speed);
}
</script>
</head>
<body bgcolor=#C0C0C0>
<div id=Message align=center style="position:absolute; left:30; top:100; width:200; z-index:2; border:2px double white; background-color: #c0c0c0; layer-background-color: #c0c0c0; visibility: hidden"></div>
<table border=2 cellSpacing=2 bgcolor=#C0C0C0 BORDERCOLOR=#C0C0C0>
<tr>
<td BORDERCOLOR=#FFFFFF rowspan=2><script>Tetris = new tetris('Box',10,20);</script></td>
<td BORDERCOLOR=#FFFFFF align=center><b>NEXT</b><br><script>Preview = new tetris('Next',4,3);</script></td>
</tr>
<tr>
<td name=Show id=Show BORDERCOLOR=#FFFFFF align=center valign=top>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
<P> </P>
</td>
</tr>
<script>
gameOver();
</script>
</body>
</html>
关键词:未完成的JS作品之二:应用面向对象思想写的俄罗斯方块