当前位置:编程学习 > JAVA >>

JavaScript 实现俄罗斯方块

[html]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>俄罗斯方块</title> 
<style type="text/css"> 
    body{ width:530px; background:#F7F7F7; margin:20px auto} 
    table#gameBoard{ border:1px solid black; border-collapse: collapse; float:left;} 
    table#gameBoard td{ width:30px; height:30px; border: 1px dotted #0cc;} 
    div#gameControl{ widows:160; float:right; height: 200px;; line-height: 200px;} 
    .font{ font-family:'微软雅黑'; font-size:18px; text-align:center;} 
    div input { width: 60px; height:25px; } 
 
</style> 
<script type="text/javascript"> 
     
 
    var T = TETRIS = { 
        aBoardGrids : [], 
        aShapes: [ 
            [0xCC00],  
            [0x8888, 0xF00],  
            [0x8C40, 0x6C00],  
            [0x4C80, 0xC600],  
            [0x44C0, 0x8E00, 0xC880, 0xE200],  
            [0x88C0, 0xE800, 0xC440, 0x2E00],  
            [0x4E00, 0x8C80, 0xE400, 0x4C40] 
        ],                                                                      //代表所有方块的形状数 
        init : function(){ 
            this.oDomBoard = document.getElementById("gameBoard"); 
            this.oDomScore = document.getElementById("score"); 
            this.aBoardGrids = new Array(18); 
            for (var rows = 0 ; rows < 18 ; rows++){ 
                this.aBoardGrids[rows] = new Array(10); 
                var oDomTr = this.oDomBoard.insertRow(-1); 
                for (var cols = 0 ; cols < 10 ; cols++){ 
                    this.aBoardGrids[rows][cols] = 0; 
                    oDomTr.insertCell(cols); 
                } 
            } 
 
            document.onkeydown = function(keyEvent){ 
                keyEvent = keyEvent || window.event; 
                var ikeyNum = keyEvent.which || keyEvent.keyCode; 
                switch(ikeyNum){ 
                    case 37://← 
                        T.oBlock.move("left"); 
                        break; 
                    case 38://↑  
                        T.oBlock.rotate((function (){ 
                            var vShape      = T.aShapes[T.iShapeIdx][ (++T.index)%T.aShapes[T.iShapeIdx].length]; 
                            var sShape      = vShape.toString(2);                                
                            sShape          = new Array(17 - sShape.length).join(0) + sShape;    
                            T.matrix        = sShape.match(/\d{4}/g);    
                            return T.matrix; 
                        })());  //变形 
                        break; 
                    case 39://→ 
                        T.oBlock.move("right"); 
                        break; 
                    case 40://↓ 
  &
补充:web前端 , JavaScript ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,