日期:2009-09-09  浏览次数:20922 次

练手的时候写的,后面写得好乱,8(

比较满意的是方块的储存和旋转,是我见过同类游戏中最简洁的

<HTML>
<head>

<title>俄罗斯方块</title>
<script>
/********************************
俄罗斯方块 Version 1.0beta
2001年10月19日 By 黄砾(Stone) (bbs.online.jx.cn)

这段脚本可以免费使用于任何非商业用途。引用时请保留本段说明。

Tetris version 1.0beta
by Li Huang, October 19th 2001
*******************************/

//存储各方块的形状
var Shapes = new Array (
    new Array (2,1,0,0,1,0,2,0,1,1),
    new Array (2,1,0,0,1,0,1,1,2,1),
    new Array (2,1,1,0,2,0,0,1,1,1),
    new Array (1,1,0,0,1,0,0,1,1,1),
    new Array (2,1,0,0,1,0,2,0,0,1),
    new Array (2,1,0,0,1,0,2,0,2,1),
    new Array (3,2,0,1,1,1,2,1,3,1));

function tetris(name,width,height) {
    this.width = width;
    this.height = height;
    document.write('<table name=' + name + ' id=' + name + ' border=1 cellSpacing=0 bgcolor=#C0C0C0 BORDERCOLOR=#C0C0C0 style=\"font-size:12pt;LINE-HEIGHT:12pt;\">');
    for (var y=0;y<this.height;y++) {
        document.write('<tr>');
        for (var x=0;x<this.width;x++)
            document.write('<td width=12 height=12>&nbsp;</td>');
        document.write('</tr>');
    }
    document.write('</table>');
    this.Box = eval(name);

    this.checkDot = function(x,y) {
        if (x<0 || y<0 || x>=this.width || y>=this.height)
            return false;
        else if (this.Box.rows(y).cells(x).borderColorDark == '#ffffff')
            return false;
        else
            return true;
    }
    this.dot = function(x,y) {
        if (this.checkDot(x,y))
            with (this.Box.rows(y).cells(x)) {
                borderColorDark = '#FFFFFF';
                borderColorLight = '#808080';
            }
    }
    this.clearDot = function(x,y) {
        with (this.Box.rows(y).cells(x)) {
            borderColorDark = '#C0C0C0';
            borderColorLight = '#C0C0C0';
        }
    }
    this.eraseLine = function() {
        var line = 0, ny=this.height-1