javascript游戏-- 俄罗斯方块 源代码

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  <HTML><HEAD>
  3.  <TITLE>俄罗斯方块</TITLE>
  4.  <META http-equiv=Content-Type content="text/html; charset=gb2312">
  5.  <META content="MSHTML 6.00.2900.3059" name=GENERATOR>
  6.  <META content="乐不思学" name=Author>
  7.  <META content="" name=Keywords>
  8.  <META content="" name=Description></HEAD>
  9.  <style>
  10.  td ...{width: 20px;height:20px;}
  11.  #box...{width:510px;1px solid #fff;}
  12.  #main...{float:left;width:340px;}
  13.  #left...{float:right;width:150px;padding:5px;}
  14.  #left1...{width:150px;border:1px solid #fff;padding:5px;color:#66CC99;}
  15.  #left2...{width:150px;color:#0066FF;padding:5px;}
  16.  #count_score...{color:yellow;}
  17.  #buttonkey...{margin-left:4px;}
  18.  </style>
  19.  <BODY   οnkeydοwn="control()" οnkeypress="addspeed()" rightMargin=50 leftMargin=200 topMargin=8>
  20.  <p>
  21.  <SCRIPT language=JavaScript src="http://www.uptoday.cn/fun/playrecord.js"></SCRIPT>
  22.  <SCRIPT language=JavaScript>
  23.  /**//*********************************************************************
  24.  作者:乐不思学 gsx123@gmail.com   QQ:254539697 
  25.  主页:http://www.uptoday.cn
  26.  日期:2007-10-31 完成
  27.  功能:纯JAVASCRIPT代码游戏 - 俄罗斯方块
  28.  ************************************************************************/
  29.  /**//* 常量 */
  30.  var TDX=18;//竖行格数
  31.  var TDY=12;//横行格数
  32.    
  33.  var speed=300;      //下降速度
  34.  var highspeed=90;   //快速下降速度
  35.  var body_back_COLOR="#000"//页面背景颜色
  36.  var back_COLOR="#000";//背景颜色
  37.  var next_back_COLOR="";  //预告框背景色
  38.  var side_COLOR="#996600"//围栏颜色
  39.  var msgGameOver="GAME OVER !"
  40.  var msg_start=" 开 始 "
  41.  var msg_stop=" 暂 停 "
  42.  var boom_num=3;    //炸弹数
  43.  var mod=0;         //难度增加模式
  44.  var q;        //时钟
  45.  var linesup_speed=15000;
  46.  var intlinesup=1;
  47.  var timer="1";
  48.  var level=new Array(1000,2000,3000,4000,5000); //升级分数
  49.  document.write("<style>td {background-color: "+back_COLOR+";}body{background-color:"+body_back_COLOR+" ;}</style>");
  50.  //********************//
  51.  /**//* 全局变量*/
  52.  var now_obj;  //当前物体
  53.  var next_obj;  //下一物体
  54.  var isStart=false;   //是否开始了游戏
  55.  var isEnd=false;     //是否游戏结束
  56.  var count_line=0;    //消除的行数
  57.  var count_score=0;   //记分
  58.  var glo_statu=new Array(); //背景单元格状态 false为空
  59.  var obj_member=new Array(); //物体成员
  60.  var d=document.getElementById;
  61.   for(i=0;i<13;i++)
  62.   ...{
  63.     obj_member[i]=new Array();
  64.   }
  65.   for(i=-4;i<=TDX;i++)      //初始化背景单元格状态
  66.   ...{ glo_statu[i]=new Array();
  67.     for(j=0;j<=TDY;j++)
  68.     ...{
  69.      if(j==0||j==TDY||i==TDX)
  70.            glo_statu[i][j]=true;
  71.      else ...{glo_statu[i][j]=false;}
  72.     }
  73.   }
  74.  //**********************************************************************************//
  75.  /**//* 定义对象*/
  76.   function obje(color,length,style,type,x0,y0,getxy)
  77.   ...{
  78.   this.color=color;  //颜色
  79.   this.length=length; //单元格数
  80.   this.style=style;   //样式
  81.   this.type=type;     //4形态
  82.   var x=new Array();  //每格x坐标
  83.   var y=new Array();  //每格y坐标
  84.   x[0]=x0;            //首格
  85.   y[0]=y0;
  86.   this.x=x;
  87.   this.y=y;
  88.   this.getxy=getxy;   //另三格坐标相对首格的偏移量
  89.   this.build=buildfunction;  //计算另三格坐标
  90.   }
  91.   function buildfunction() //由偏移量构造另三格坐标
  92.   ...{
  93.    with(this)
  94.    ...{
  95.     x[1]=x[0]+getxy[0];
  96.     y[1]=y[0]+getxy[1];
  97.     x[2]=x[0]+getxy[2];
  98.     y[2]=y[0]+getxy[3];
  99.     x[3]=x[0]+getxy[4];
  100.     y[3]=y[0]+getxy[5];
  101.    }
  102.   }
  103.  var objNum=0;
  104.  //
  105.  // [1][2]   [2][0][3]   [3]       
  106.  //    [0]   [1]         [0]             [1]
  107.  //    [3]               [2][1]    [3][0][2]
  108.  //
  109.  var tt=new Array();var color="red"var len=4;var sty=0;var x0=-2;var y0=5;
  110.      tt[0]=new Array(-1,-1,-1,0,1,0);
  111.      tt[1]=new Array(1,-1,0,-1,0,1)
  112.      tt[2]=new Array(1,1,1,0,-1,0);
  113.      tt[3]=new Array(-1,1,0,1,0,-1);
  114.   for(i=0;i<4;i++)
  115.   ...{
  116.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  117.    obj_member[sty][i].build();
  118.   }
  119.  objNum++;
  120.  //
  121.  //    [2][1]    [1]               [3]
  122.  //    [0]       [2][0][3]         [0]      [3][0][2]
  123.  //    [3]                      [1][2]            [1]
  124.  //
  125.      color="#CC6666";sty++;
  126.      tt[0]=new Array(-1,1,-1,0,1,0);
  127.      tt[1]=new Array(-1,-1,0,-1,0,1)
  128.      tt[2]=new Array(1,-1,1,0,-1,0);
  129.      tt[3]=new Array(1,1,0,1,0,-1);
  130.   for(i=0;i<4;i++)
  131.   ...{
  132.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  133.    obj_member[sty][i].build();
  134.   }
  135.  objNum++;
  136.  //
  137.  //    [2]         [3]                [1]
  138.  // [1][0][3]   [2][0]   [3][0][1]    [0][2]      
  139.  //                [1]      [2]       [3]
  140.  // 
  141.      color="blue";sty++;
  142.      tt[0]=new Array(0,-1,-1,0,0,1);
  143.      tt[1]=new Array(1,0,0,-1,-1,0)
  144.      tt[2]=new Array(0,1,1,0,0,-1);
  145.      tt[3]=new Array(-1,0,0,1,1,0);
  146.   for(i=0;i<4;i++)
  147.   ...{
  148.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  149.    obj_member[sty][i].build();
  150.   }
  151.  objNum++;
  152.  //                [3]                  [3]
  153.  //                [0]                  [0]
  154.  // [1][2][0][3]   [2]   [1][2][0][3]   [2]       
  155.  //                [1]                  [1]            
  156.  // 
  157.      color="green";sty++;
  158.      tt[0]=new Array(0,-2,0,-1,0,1);
  159.      tt[1]=new Array(2,0,1,0,-1,0);
  160.      tt[2]=new Array(0,-2,0,-1,0,1);
  161.      tt[3]=new Array(2,0,1,0,-1,0);
  162.   for(i=0;i<4;i++)
  163.   ...{
  164.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  165.    obj_member[sty][i].build();
  166.   }
  167.  objNum++;
  168.  //                                 
  169.  //   [1]           [2][3]    [1]         [2][3]
  170.  //   [0][2]     [1][0]       [0][2]   [1][0]       
  171.  //      [3]                     [3]                 
  172.  // 
  173.      color="#660099";sty++;
  174.      tt[0]=new Array(-1,0,0,1,1,1);
  175.      tt[1]=new Array(0,-1,-1,0,-1,1);
  176.      tt[2]=new Array(-1,0,0,1,1,1);
  177.      tt[3]=new Array(0,-1,-1,0,-1,1);
  178.   for(i=0;i<4;i++)
  179.   ...{
  180.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  181.    obj_member[sty][i].build();
  182.   }
  183.  objNum++;
  184.  //                                 
  185.  //             
  186.  //   [0][1]           
  187.  //   [2][3]                                  
  188.  // 
  189.      color="yellow";sty++;
  190.      tt[0]=new Array(0,1,1,0,1,1);
  191.      tt[1]=new Array(0,1,1,0,1,1);
  192.      tt[2]=new Array(0,1,1,0,1,1);
  193.      tt[3]=new Array(0,1,1,0,1,1);
  194.   for(i=0;i<4;i++)
  195.   ...{
  196.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  197.    obj_member[sty][i].build();
  198.   }
  199.  objNum++;
  200.  //                                 
  201.  //    [1]                     [1]    [1][0]
  202.  // [2][0]     [1][0]       [2][0]       [2][3]       
  203.  // [3]           [2][3]    [3]                   
  204.  // 
  205.      color="#999966";sty++;
  206.      tt[0]=new Array(-1,0,0,-1,1,-1);
  207.      tt[1]=new Array(0,-1,1,0,1,1);
  208.      tt[2]=new Array(-1,0,0,-1,1,-1);
  209.      tt[3]=new Array(0,-1,1,0,1,1);
  210.   for(i=0;i<4;i++)
  211.   ...{
  212.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  213.    obj_member[sty][i].build();
  214.   }
  215.  objNum++; //7
  216.  //                                 
  217.  //              [2][3]         
  218.  // [0]  [2]                      
  219.  // [1]  [3]     [0][1]       
  220.  // 
  221.      color="#66FF66";sty++;
  222.      tt[0]=new Array(1,0,0,2,1,2);
  223.      tt[1]=new Array(0,1,-2,0,-2,1);
  224.      tt[2]=new Array(1,0,0,2,1,2);
  225.      tt[3]=new Array(0,1,-2,0,-2,1);
  226.   for(i=0;i<4;i++)
  227.   ...{
  228.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  229.    obj_member[sty][i].build();
  230.   }
  231.  objNum++;
  232.  //                                 
  233.  // [1]          [2][3]         
  234.  // [0]  [2]                      
  235.  //      [3]  [1][0]       
  236.  // 
  237.      color="#66FF66";sty++;
  238.      tt[0]=new Array(-1,0,0,2,1,2);
  239.      tt[1]=new Array(0,-1,-2,0,-2,1);
  240.      tt[2]=new Array(-1,0,0,2,1,2);
  241.      tt[3]=new Array(0,-1,-2,0,-2,1);
  242.   for(i=0;i<4;i++)
  243.   ...{
  244.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  245.    obj_member[sty][i].build();
  246.   }
  247.  objNum++;
  248.  //                                 
  249.  //   [1]            [3]   [3] [2]   [2] 
  250.  //   [0]       [1][0]       [0]        [0][1]    
  251.  // [2] [3]          [2]     [1]     [3]
  252.  //  
  253.      color="#66FF66";sty++;
  254.      tt[0]=new Array(-1,0,1,-1,1,1);
  255.      tt[1]=new Array(0,-1,1,1,-1,1);
  256.      tt[2]=new Array(1,0,-1,-1,-1,1);
  257.      tt[3]=new Array(0,1,-1,-1,1,-1);
  258.   for(i=0;i<4;i++)
  259.   ...{
  260.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  261.    obj_member[sty][i].build();
  262.   }
  263.  objNum++;
  264.  //                                 
  265.  //   [1][0][2]    [2]          [3]          [1]
  266.  //                [0]  [3]             [3]  [0]
  267.  //      [3]       [1]       [2][0][1]       [2]
  268.  //                    
  269.      color="#66FF66";sty++;
  270.      tt[0]=new Array(0,-1,0,1,2,0);
  271.      tt[1]=new Array(1,0,-1,0,0,2);
  272.      tt[2]=new Array(0,-1,0,1,-2,0);
  273.      tt[3]=new Array(1,0,-1,0,0,-2);
  274.   for(i=0;i<4;i++)
  275.   ...{
  276.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  277.    obj_member[sty][i].build();
  278.   }
  279.  objNum++;
  280.  //                                 
  281.  //   [1]                  
  282.  // [2] [0]               
  283.  //   [3]                  
  284.  //  
  285.      color="#66FF66";sty++;
  286.      tt[0]=new Array(-1,-1,0,-2,1,-1);
  287.      tt[1]=new Array(-1,-1,0,-2,1,-1);
  288.      tt[2]=new Array(-1,-1,0,-2,1,-1);
  289.      tt[3]=new Array(-1,-1,0,-2,1,-1);
  290.   for(i=0;i<4;i++)
  291.   ...{
  292.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  293.    obj_member[sty][i].build();
  294.   }
  295.  objNum++;
  296.  //                                 
  297.  //   [1]  [0]                
  298.  //                 
  299.  //   [3]  [2]                
  300.  //  
  301.      color="#33CCCC";sty++;
  302.      tt[0]=new Array(0,-2,2,0,2,-2);
  303.      tt[1]=new Array(0,-2,2,0,2,-2);
  304.      tt[2]=new Array(0,-2,2,0,2,-2);
  305.      tt[3]=new Array(0,-2,2,0,2,-2);
  306.   for(i=0;i<4;i++)
  307.   ...{
  308.    obj_member[sty][i]=new obje(color,len,sty,i,x0,y0,tt[i]);
  309.    obj_member[sty][i].build();
  310.   }
  311.  objNum++;
  312.  var temp1=Math.floor(Math.random()*(7));
  313.  var temp2=Math.floor(Math.random()*(3));
  314.  now_obj=obj_member[temp1][temp2];    //初始化当前物体!!
  315.  var boom_added=false;
  316.  function getNextObj() //{{生成下一物体}}
  317.  ...{
  318.     if(count_score>=level[4])  //难度控制
  319.       ...{ if(mod=="0")...{speed=90;}
  320.         else if(mod=="2")      
  321.         ...{
  322.           if(timer!="1"&&intlinesup==5)
  323.            ...{clearInterval(timer);timer=setInterval("linesup()",5000);intlinesup=6;}
  324.          }
  325.         else thenum=objNum;
  326.       document.getElementById("level").innerHTML=6;
  327.       if(boom_added)...{boom_added=false;boom_num++;pic="";
  328.           for(k=1;k<=boom_num;k++)
  329.              pic+=" ※";
  330.        document.getElementById("boom").innerHTML=pic;
  331.         }
  332.       }
  333.    else if(count_score>=level[3]&&count_score<level[4])  //难度控制
  334.       ...{ if(mod=="0")...{speed=110;}
  335.         else if(mod=="2")      
  336.         ...{
  337.           if(timer!="1"&&intlinesup==4)
  338.            ...{clearInterval(timer);timer=setInterval("linesup()",6500);intlinesup=5;}
  339.          }
  340.         else thenum=objNum-1;
  341.       document.getElementById("level").innerHTML=5;
  342.       if(!boom_added)...{boom_added=true;boom_num++;pic="";
  343.           for(k=1;k<=boom_num;k++)
  344.            pic+=" ※";
  345.         document.getElementById("boom").innerHTML=pic;
  346.           }
  347.       }
  348.    else if(count_score>=level[2]&&count_score<level[3])
  349.      ...{ if(mod=="0")...{speed=150;}
  350.        else if(mod=="2")
  351.        ...{if(timer!="1"&&intlinesup==3)...{clearInterval(timer);timer=setInterval("linesup()",9000);intlinesup=4;}}
  352.        else thenum=(objNum-2);
  353.       document.getElementById("level").innerHTML=4;}
  354.    else if(count_score>=level[1]&&count_score<level[2])
  355.      ...{ if(mod=="0")...{speed=180;}
  356.        else if(mod=="2")
  357.          ...{if(timer!="1"&&intlinesup==2)...{clearInterval(timer);timer=setInterval("linesup()",12000);intlinesup=3;}}
  358.        else thenum=(objNum-3);
  359.       document.getElementById("level").innerHTML=3;}
  360.    else if(count_score>=level[0]&&count_score<level[1])
  361.       ...{ if(mod=="0")...{speed=220;}
  362.         else if(mod=="2")
  363.            ...{if(timer=="1")...{timer=setInterval("linesup()",15000);intlinesup=2;}}
  364.         else thenum=(objNum-4);
  365.       document.getElementById("level").innerHTML=2;}
  366.    else 
  367.      ...{     
  368.      thenum=7;}
  369.  var temp1=Math.floor(Math.random()*(thenum));
  370.  var temp2=Math.floor(Math.random()*(3));
  371.  next_obj=obj_member[temp1][temp2]; 
  372.  }
  373.  getNextObj();     //初始化下一物体!!
  374.  //**********************************************************************************//
  375.  /**//* 函数 /
  376.  /*-------------------------*/
  377.  function control() //  键盘控制
  378.  ...{
  379.  var key=event.keyCode;
  380.    switch(key)
  381.    ...{
  382.    case 37:moveleft(now_obj); break;   //  ←
  383.    case 39:moveright(now_obj); break;  //  →
  384.    case 40:                            //  ↓
  385.     // if(!isStart)
  386.       // autodown(now_obj);
  387.      //else
  388.      // {
  389.        stop();
  390.        q=setInterval("movedown(now_obj)",highspeed);
  391.       // }
  392.      break;                              
  393.    case 38:turn(now_obj); break;       //  ↑
  394.    case 32:boom(); break;       //  ↑
  395.    }
  396.  }
  397.  function addspeed() //加速
  398.  ...{
  399.     if(event.keyCode==40&&isStart)
  400.     ...{
  401.      speed=highspeed;
  402.     }
  403.  }
  404.  function highspeed() //
  405.  ...{  
  406.        if(!q)...{autodown();}
  407.        else...{
  408.        stop();
  409.        q=setInterval("movedown(now_obj)",highspeed);
  410.        }
  411.  }
  412.  function show(obj) //显示物体
  413.  ...{
  414.   for(i=0;i<obj.length;i++)
  415.   ...{if(obj.x[i]>=0)
  416.     ...{
  417.    document.getElementById("d_"+obj.x[i]+"_"+obj.y[i]).style.background=obj.color;
  418.     }
  419.    glo_statu[obj.x[i]][obj.y[i]]=true;
  420.   }
  421.  }
  422.  function hid(obj) //消失物体
  423.  ...{
  424.    for(i=0;i<obj.length;i++)
  425.   ...{
  426.    if(obj.x[i]>=0)
  427.    ...{
  428.    document.getElementById("d_"+obj.x[i]+"_"+obj.y[i]).style.background=back_COLOR;
  429.    }
  430.    glo_statu[obj.x[i]][obj.y[i]]=false;
  431.   }
  432.  }
  433.  function array_walk(arr,flag)//处理数组中每一项
  434.  ...{
  435.    for(i=0;i<arr.length;i++)
  436.    ...{
  437.       switch(flag)
  438.       ...{
  439.       case "+":arr[i]++; break;
  440.       case "-":arr[i]--; break;
  441.       case "false": glo_statu[arr.x[i]][arr.y[i]]=false;break;
  442.       case "true" : glo_statu[arr.x[i]][arr.y[i]]=truebreak;
  443.       }
  444.     
  445.    }
  446.  }
  447.  function canmove(obj,to) //能否继续移动 ??
  448.  ...{
  449.  var can=true;
  450.  array_walk(obj,"false");
  451.    switch(to)
  452.    ...{
  453.     case "down": array_walk(obj.x,"+");break;
  454.     case "left": array_walk(obj.y,"-");break;
  455.     case "right":array_walk(obj.y,"+");break;
  456.    }
  457.    for(i=0;i<obj.x.length;i++)
  458.   ...{
  459.    if(glo_statu[obj.x[i]][obj.y[i]]==true)
  460.    ...{
  461.     can=false;
  462.     break;
  463.    }  
  464.   }
  465.    switch(to)
  466.    ...{
  467.     case "down": array_walk(obj.x,"-");break;
  468.     case "left": array_walk(obj.y,"+");break;
  469.     case "right":array_walk(obj.y,"-");break;
  470.    }
  471.  array_walk(obj,"true");
  472.  return can;
  473.  }  
  474.  function autodown()    //开始自动下移 start
  475.   ...{
  476.    if(!isEnd)
  477.    ...{
  478.    q=setInterval("movedown(now_obj)",speed);
  479.    if(!isStart)isStart=true;
  480.    }
  481.   document.getElementById("butt").value=msg_stop;
  482.   }
  483.  function stop() ...{clearInterval(q);} //停止 stop
  484.  function movedown(obj) //下移 ↓↓
  485.  ...{
  486.   if(canmove(obj,"down"))
  487.    ...{
  488.      hid(obj);
  489.      for(i=0;i<obj.length;i++)
  490.      ...{
  491.      obj.x[i]++;
  492.      }
  493.      show(obj);
  494.    }
  495.   else              //触底
  496.    ...{
  497.    stop();
  498.    check_clearline(obj);
  499.     for(y=0;y<obj.length;y++) //判断游戏结束
  500.      ...{
  501.       if(obj.x[y]<2)...{isEnd=true;}
  502.       else...{isEnd=false;}
  503.      }
  504.     if(isEnd)
  505.      ...{
  506.       window.alert(msgGameOver);
  507.       document.getElementById("butt").value="重来";
  508.      }
  509.     else...{
  510.       now_obj=next_obj;
  511.       now_obj.x[0]=x0;now_obj.y[0]=y0;now_obj.build();
  512.       fornext(next_obj,"hidden");
  513.        getNextObj();
  514.       fornext(next_obj,"show");
  515.      //show(now_obj);
  516.      //window.alert(now_obj.x);
  517.      autodown();
  518.      }
  519.    }
  520.  }
  521.  function check_clearline(obj) //是否有满行,清除行
  522.  ...{ 
  523.    var clearnum=0;
  524.    var c=0;
  525.      var max=obj.x[0];var min=obj.x[0];
  526.        for(i=1;i<obj.length;i++)
  527.        ...{
  528.          if(obj.x[i]>max)max=obj.x[i];
  529.          else if(obj.x[i]<min)min=obj.x[i];
  530.        }
  531.      for(i=max;i>=min;i--)
  532.      ...{ 
  533.       var isfull=true;
  534.        for(j=1;j<TDY;j++)
  535.        ...{
  536.         if(glo_statu[i][j]==false)isfull=false;
  537.        }
  538.         if(isfull)
  539.         ...{
  540.          clearline(i);
  541.          clearnum++;
  542.          lines_down(i);
  543.          i=max+1;
  544.        //if(mod=="2")linesup();
  545.         }
  546.      }
  547.    
  548.     count_score=parseInt(document.getElementById("count_score").innerHTML);
  549.      switch(clearnum)   //加分
  550.       ...{
  551.       case 0: break;
  552.       case 1: count_score+=100;break;
  553.       case 2: count_score+=300;break;
  554.       case 3: count_score+=500;break;
  555.       case 4: count_score+=800;break;     
  556.       }
  557.     document.getElementById("count_score").innerHTML=count_score; 
  558.  }
  559.  function clearline(i) //清除行
  560.  ...{
  561.      for(j=1;j<TDY;j++)
  562.      ...{
  563.    document.getElementById("d_"+i+"_"+j).style.background=back_COLOR;
  564.    glo_statu[i][j]=false;
  565.  //document.getElementById("d_"+i+"_"+j).innerHTML=glo_statu[i][j];
  566.      }
  567.  line=parseInt(document.getElementById("count_line").innerHTML);
  568.  line+=1;
  569.  document.getElementById("count_line").innerHTML=line;
  570.  }
  571.  function lines_down(lineKilled) //清除行后下移其上方块
  572.  ...{
  573.   for(i=lineKilled-1;i>0;i--)
  574.   ...{      
  575.      for(j=1;j<TDY;j++)
  576.      ...{
  577.        if(glo_statu[i][j])
  578.        ...{
  579.        temp=i;
  580.        var tempcolor=document.getElementById("d_"+i+"_"+j).style.background;
  581.        document.getElementById("d_"+i+"_"+j).style.background=back_COLOR;
  582.        glo_statu[temp][j]=false;
  583.        temp++;
  584.        glo_statu[temp][j]=true;
  585.        document.getElementById("d_"+temp+"_"+j).style.background=tempcolor;
  586.        }
  587.      }
  588.   }
  589.   
  590.  }
  591.  function moveleft(obj) //左移  ← ←
  592.  ...{
  593.    if(canmove(obj,"left"))
  594.    //if(true)
  595.    ...{
  596.      hid(obj);
  597.      for(i=0;i<obj.length;i++)
  598.      ...{
  599.      obj.y[i]--;
  600.      }
  601.      show(obj);
  602.    }
  603.  }
  604.  function moveright(obj) //右移  → →
  605.  ...{
  606.    if(canmove(obj,"right"))
  607.   // if(true)
  608.    ...{
  609.      hid(obj);
  610.      for(i=0;i<obj.length;i++)
  611.      ...{
  612.      obj.y[i]++;
  613.      }
  614.      show(obj);
  615.    }
  616.  }
  617.  function turn(obj) //旋转
  618.  ...{ 
  619.    typ=obj.type;
  620.    typ++;
  621.    if(typ==4)...{typ=0;}
  622.    styl=obj.style;
  623.      
  624.      temp_obj=obj_member[styl][typ];
  625.      temp_obj.x[0]=obj.x[0];
  626.      temp_obj.y[0]=obj.y[0];  
  627.      temp_obj.build();
  628.   var can=true;
  629.     for(h=0;h<temp_obj.legth;h++)
  630.     ...{
  631.        if(glo_statu[temp_obj.x[h]][temp_obj.y[h]]==true)
  632.        ...{
  633.         can=false;
  634.         break;
  635.        }  
  636.     }
  637.     if(can)
  638.      ...{
  639.      hid(obj);
  640.      now_obj=temp_obj;    
  641.      show(now_obj);
  642.      }
  643.  }
  644.  function linesup() //抬升
  645.  ...{hid(now_obj);
  646.   for(i=2;i<TDX;i++)
  647.   ...{      
  648.      for(j=1;j<TDY;j++)
  649.      ...{
  650.        if(glo_statu[i][j])
  651.        ...{
  652.        temp=i;
  653.        var tempcolor=document.getElementById("d_"+i+"_"+j).style.background;
  654.        document.getElementById("d_"+i+"_"+j).style.background=back_COLOR;
  655.        glo_statu[temp][j]=false;
  656.        temp--;
  657.        glo_statu[temp][j]=true;
  658.       // window.alert("d_"+temp+"_"+j);
  659.        document.getElementById("d_"+temp+"_"+j).style.background=tempcolor;
  660.        }
  661.      }
  662.   }
  663.    for(j=1;j<TDY;j++)
  664.    ...{
  665.      randtemp=Math.floor(Math.random()*(2));    //window.alert(randtemp);
  666.      if(randtemp==1)...{glo_statu[TDX-1][j]=true;document.getElementById("d_"+(TDX-1)+"_"+j).style.background="#CC00CC";}
  667.      else  ...{glo_statu[TDX-1][j]=false;document.getElementById("d_"+(TDX-1)+"_"+j).style.background=back_COLOR;}
  668.    }
  669.    show(now_obj);
  670.  }
  671.  //**********************************************************************************//
  672.   document.write(" <div id=box align=center><div id=main><table>")
  673.   var css;
  674.   for(i=0;i<=TDX;i++)
  675.   ...{
  676.     document.write("<tr>")
  677.     for(j=0;j<=TDY;j++)
  678.      ...{
  679.      if(j==0||j==TDY||i==TDX)...{css=side_COLOR;} else...{css=back_COLOR;}//围栏颜色
  680.      document.write("<td id=d_"+i+"_"+j+" style="background:"+css+""></td>"
  681.      }
  682.     document.write("</tr>")
  683.   }
  684.   document.write("</table></div>");
  685.   document.write("<div id=left><div id=left1><table>");
  686.   for(i=0;i<5;i++)
  687.   ...{
  688.     document.write("<tr>")
  689.     for(j=0;j<5;j++)
  690.      ...{
  691.      document.write("<td id=n_"+i+"_"+j+" style="background:"+next_back_COLOR+""></td>"
  692.      }
  693.     document.write("</tr>")
  694.   }
  695.   document.write("</table>");
  696.  function fornext(obj,color) //显示/隐藏下一物体
  697.  ...{
  698.  if(color=="hidden")...{color=next_back_COLOR;}
  699.  else if(color=="show")...{color=obj.color;}
  700.  var px=new Array();
  701.  var py=new Array();
  702.   px[0]=2;py[0]=2;
  703.   px[1]=px[0]+obj.getxy[0];
  704.   py[1]=py[0]+obj.getxy[1];
  705.   px[2]=px[0]+obj.getxy[2];
  706.   py[2]=py[0]+obj.getxy[3];
  707.   px[3]=px[0]+obj.getxy[4];
  708.   py[3]=py[0]+obj.getxy[5];
  709.   for(i=0;i<px.length;i++)
  710.    document.getElementById("n_"+px[i]+"_"+py[i]).style.background=color;
  711.  }
  712.  fornext(next_obj,"show");
  713.  function button(t) //按钮
  714.  ...{
  715.   if(t==msg_start)...{
  716.   autodown(now_obj);
  717.   document.getElementById("butt").value=msg_stop;
  718.   mod=document.getElementById("mod").value;
  719.   }
  720.   else if(t==msg_stop)...{
  721.    stop();
  722.    document.getElementById("butt").value=msg_start;
  723.    }
  724.   else
  725.    document.location.reload();
  726.  document.body.focus();
  727.  }
  728.      pic="";
  729.      for(k=1;k<=boom_num;k++)
  730.        pic+="※ "
  731.   </SCRIPT>
  732.   <BR>
  733.   炸弹:<span id="boom"><SCRIPT LANGUAGE="JavaScript">document.write(pic);</SCRIPT></span>
  734.   <BR>
  735.    行数: <span id="count_line">0</span><BR>
  736.    得分:<span id="count_score">0</span><BR>
  737.    等级:<span id="level">1</span>
  738.  </div>
  739.   <div id="left2">
  740.    <div id="buttonkey">
  741.   
  742.   升级后:
  743.   <SELECT NAME="" id="mod" οnchange="mod=this.value;document.body.focus();">
  744.      <OPTION VALUE="0" SELECTED>加  速</OPTION>
  745.      <OPTION VALUE="1">加方块</OPTION>
  746.      <OPTION VALUE="2">抬  升</OPTION>
  747.   </SELECT>
  748.     <br>
  749.     <SCRIPT LANGUAGE="JavaScript">
  750.      document.write("<INPUT TYPE="button" value=""+msg_start+"" id="butt" οnclick="button(this.value)">");
  751.     </SCRIPT>
  752.     <BR>
  753.     </div><BR><BR><BR>
  754.   键盘<BR> 
  755.   ← ↓ → 移动<BR>
  756.   ↑ 旋转<BR>
  757.   空格 使用炸弹
  758.    </div>
  759.  </div>
  760.  </div>
  761.   
  762.  </P></BODY></HTML>
  763.  <SCRIPT LANGUAGE="JavaScript">
  764.    function boom() //炸弹
  765.    ...{
  766.      if(boom_num>0)
  767.      ...{
  768.    
  769.      boom_num--;
  770.      max=now_obj.x[0];
  771.        for(i=1;i<now_obj.length;i++)
  772.        ...{
  773.          if(now_obj.x[i]>max)max=now_obj.x[i];
  774.        }
  775.       t=max+1;
  776.      n=now_obj.y[0];
  777.      while(glo_statu[t][n]==false)t++;
  778.      for(i=n-3;i<=n+3;i++)
  779.      ...{
  780.         for(j=t-3;j<=t+3;j++)
  781.         ...{
  782.            if(i>0&&i<TDY&&j>0&&j<TDX)
  783.            ...{
  784.              glo_statu[j][i]=false;
  785.             document.getElementById("d_"+j+"_"+i).style.background=back_COLOR;
  786.            }
  787.         }
  788.      }
  789.      pic="";
  790.      for(k=1;k<=boom_num;k++)
  791.        pic+=" ※"
  792.     document.getElementById("boom").innerHTML=pic;
  793.      
  794.  //autodown();
  795.    }
  796.    }
  797.  </SCRIPT> 
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值