大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> Script -> 一个简单的俄罗斯方块脚本

一个简单的俄罗斯方块脚本

时间: 2021-07-31 作者:daque

<html><head><meta name="title" content="jscript simple tetris"><meta content="text/html; charset=utf8" http-equiv=content-type><title>俄罗斯方块</title><style>body {margin:0;background:black;}td {height:20;width:20;}#block_div {position:absolute;z-index:1;width:80;}#table_div {position:absolute;z-index:0;width:320;}#nblock_div {position:absolute;z-index:2;font:48 system;color:red;}#title_div {position:absolute;left:326;top:7;font-size:9pt;color:white}#infobar_div {position:absolute;left:396;top:416;}#infobar2_div {position:absolute;left:396;top:480;font-size:9pt;color:white}#infobar2_div a{color:99ccff;font:system;text-decoration:none}</style> <script id=clienteventhandlersjs language=javascript> if (document.all){var n_width = 800;var n_height = 600;var n_left = math.round( screen.width/2 ) - n_width/2;var n_top = math.round( screen.height/2 ) - n_height/2;var n_incstep = 20;var curblcok,nextblock;var arr_curblock = new array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);var curx,cury;var speed=1;var maxspeed=9;var clr_per_line=18;var pause=0;var gameover=0;var colors = new array("#999999","#0000ff","#80ffff","#80ff80","#ffff00","#ff8000","#ff00ff","#ff0000");var cid;var ncid;var blocks = new array("tt_o1","tt_t2","tt_z1","tt_s1","tt_l1","tt_j1","tt_i2");var bid;var killedlines=0; var tt_o1 = new array(0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0);var tt_o2 = new array(0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0);var tt_o3 = new array(0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0);var tt_o4 = new array(0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0); var tt_t1 = new array(0,0,0,0,0,1,0,0,1,1,0,0,0,1,0,0);var tt_t2 = new array(0,0,0,0,0,0,0,0,1,1,1,0,0,1,0,0);var tt_t3 = new array(0,0,0,0,0,1,0,0,0,1,1,0,0,1,0,0);var tt_t4 = new array(0,0,0,0,0,1,0,0,1,1,1,0,0,0,0,0); var tt_z1 = new array(0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0);var tt_z2 = new array(0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0);var tt_z3 = new array(0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0);var tt_z4 = new array(0,0,1,0,0,1,1,0,0,1,0,0,0,0,0,0); var tt_s1 = new array(0,0,0,0,0,1,1,0,1,1,0,0,0,0,0,0);var tt_s2 = new array(0,0,0,0,0,1,0,0,0,1,1,0,0,0,1,0);var tt_s3 = new array(0,0,0,0,0,0,1,1,0,1,1,0,0,0,0,0);var tt_s4 = new array(0,1,0,0,0,1,1,0,0,0,1,0,0,0,0,0); var tt_l1 = new array(0,1,0,0,0,1,0,0,0,1,1,0,0,0,0,0);var tt_l2 = new array(0,0,0,0,0,0,1,0,1,1,1,0,0,0,0,0);var tt_l3 = new array(0,0,0,0,0,1,1,0,0,0,1,0,0,0,1,0);var tt_l4 = new array(0,0,0,0,0,1,1,1,0,1,0,0,0,0,0,0); var tt_j1 = new array(0,0,1,0,0,0,1,0,0,1,1,0,0,0,0,0);var tt_j2 = new array(0,0,0,0,1,1,1,0,0,0,1,0,0,0,0,0);var tt_j3 = new array(0,0,0,0,0,1,1,0,0,1,0,0,0,1,0,0);var tt_j4 = new array(0,0,0,0,0,1,0,0,0,1,1,1,0,0,0,0); var tt_i1 = new array(0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0);var tt_i2 = new array(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1);var tt_i3 = new array(0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0);var tt_i4 = new array(0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1); var table = new array( 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,0,0,0,0,0,0,0,0,0,0,0,0,1,1, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1)}elsealert("you need ie4+ to play tetris!") function dimension2(row,col,num){ var i = row * num + col; return (this[i]);}array.prototype.getd = dimension2; function showblock(x,y,block_type,color){ for (var i=0;i<block_tbl.rows.length;i++){ for (var j=0;j<block_tbl.rows(i).cells.length;j++){ var d2 = i * 4 + j; if (block_type[d2]==1){ block_tbl.rows(i).cells(j).style.background = color; } else{ block_tbl.rows(i).cells(j).style.background = ""; } } } block_div.style.pixelleft=x; block_div.style.pixeltop=y;} function showblock1(x,y,block_type,color,obj_tabid,obj_divid){ for (var i=0;i<obj_tabid.rows.length;i++){ for (var j=0;j<obj_tabid.rows(i).cells.length;j++){ var d2 = i * 4 + j; if (block_type[d2]==1){ obj_tabid.rows(i).cells(j).style.background = color; } else{ obj_tabid.rows(i).cells(j).style.background = ""; } } } obj_divid.style.pixelleft=x; obj_divid.style.pixeltop=y;} function change(inc){ var type = curblock.substr(0,4); var num = curblock.substr(curblock.length-1); num = parseint(num) + inc; if (num>4||num<1) num -= 4*inc; type += num; eval("arr_tmp = " + type + ";"); if (canmove(curx,cury,arr_tmp)){ curblock = type; eval("arr_curblock = " + curblock + ";"); eval("showblock(block_div.style.pixelleft,block_div.style.pixeltop," + curblock + ",colors[" + cid + "]);"); }} function canmove(x,y,block){ for (i=0;i<4;i++){ for (j=0;j<4;j++){ if (block.getd(i,j,4)&table.getd(y/n_incstep+i,x/n_incstep+j,16)) return false; } } return true;} function newblock(){ curblock = nextblock; cid = ncid; bid = math.round(math.random()*(blocks.length-1)); ncid = math.round(math.random()*(colors.length-1)); nextblock = blocks[bid]; eval("arr_curblock = " + curblock + ";"); eval("showblock(120,0," + curblock + ",colors[" + cid + "]);"); eval("arr_curblock = " + curblock + ";"); eval("showblock1(466,116," + nextblock + ",colors[" + ncid + "],nblock_tbl,nblock_div);");} function saveblock(){ for (i=0;i<4;i++){ for (j=0;j<4;j++){ table[(cury/n_incstep+i)*16+curx/n_incstep+j]|=arr_curblock[i*4+j]; if (arr_curblock[i*4+j]==1) if ((cury/n_incstep+i<21)&&(curx/n_incstep+j>1)&&(curx/n_incstep+j<14)) table_tbl.rows(cury/n_incstep+i).cells(curx/n_incstep+j).style.background = colors[cid]; if (table[(cury/n_incstep+i)*16+curx/n_incstep+j]!=1) table_tbl.rows(cury/n_incstep+i).cells(curx/n_incstep+j).style.background = "black"; } }} function delline(line){ for(i=line;i>0;i--){ for(j=2;j<14;j++){ table[i*16+j]=table[(i-1)*16+j]; } } table_tbl.deleterow(line); table_tbl.insertrow(0); for (i=0;i<16;i++){ table_tbl.rows(0).insertcell(); if (i<2||i>13) table_tbl.rows(0).cells(i).style.background="navy"; } killedlines++; cll.innertext=parseint(cll.innertext)+1;} function dellines(){ var c,d,i,j; d=0; cury=block_div.style.pixeltop; for(i=(cury/20+3);i>cury/20-1;i--){ c=0; for(j=2;j<14;j++){ 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 = "game over";} function document_onkeydown() { if (gameover==1) return; with (block_div.style){ curx = pixelleft; cury = pixeltop; switch (event.keycode){ case 37: if (canmove(curx-n_incstep,cury,arr_curblock)) pixelleft-=n_incstep; break; case 38: change(1); break; case 39: if (canmove(curx+n_incstep,cury,arr_curblock)) pixelleft+=n_incstep; break; case 40: 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){ clearinterval(gameinterval); pause=1; } else{ gameinterval=window.setinterval("handle_interval()",(maxspeed-speed+1)*60); pause=0; } break; case 90: change(1); break; case 88: 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){ 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 language=javascript for=document event=onkeydown> if (document.all) document_onkeydown()</script> </head> <body language=javascript topmargin="0" leftmargin="0" scroll="no" > <div id=block_div style="left:60;top:0"><table id=block_tbl border=0 cellspacing=0 cellpadding=0><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></table></div> <div id=nblock_div><table id=nblock_tbl border=0 cellspacing=0 cellpadding=0><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></table></div> <div id=table_div><table id=table_tbl border=0 cellspacing=0 cellpadding=0><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></table></div> <div id=title_div nowrap style="width: 407; height: 24; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12"> <p align="center">请输出游戏速率(0-9): <input type="text" size=3 id="speedin" style="font-size: 9pt" name="superso">  <button onclick="begintet()" id="but"> <font style="font-size: 9pt" face="arial black" color="#ff0000">ok</font></button></div> <div id=infobar_div><table border=1 bordercolor=#000000 cellspacing=0 cellpadding=0><tr align=center><td style="color:99ccff;font-size: 9pt;width:60;">游戏速率:</td><td style="color:red;font-size: 9pt;" id=spd>1</td><td style="color:99ccff;font-size: 9pt;width:60;">总 得 分:</td> <td style="color:red;font-size: 9pt;" id=sco>0</td><td style="color:99ccff;font-size: 9pt;width:60;">废除行数:</td><td style="color:red;font-size: 9pt;" id=cll>0</td></tr></table></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(){document.all.speedin.disabled=truedocument.all.but.disabled=truespeed=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> </body></html>

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.