黑客X档案官方论坛's Archiver

yw9sky 发表于 2006-10-11 09:31

俄罗斯方块

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>

<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>Please input speed (1-9) to begin: <input type="text" size=8 id="speedin"> <button onClick="begintet()" id="but">Submit!</button></div>


<div id=infobar_div>
<table border=1 bordercolor=navy cellspacing=0 cellpadding=0>
<tr align=center>
<td style="color:99ccff;font:12 system;width:56;">Speed:</td>
<td style="color:red;font:12 system;" id=spd>1</td>
<td style="color:99ccff;font:12 system;width:86;">Total Score:</td>
<td style="color:red;font:12 system;" id=sco>0</td>
<td style="color:99ccff;font:12 system;width:96;">Cleared Lines:</td>
<td style="color:red;font:12 system;" 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=true
document.all.but.disabled=true
speed=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>
</html>

jiantsoft1 发表于 2008-11-29 00:46

真牛啊 ::36:: ::36::

风※云 发表于 2008-11-29 09:19

强悍!!!::23::

皇夜 发表于 2008-11-30 11:58

好啊::04:: ::04::

页: [1]


Powered by Discuz! 6.1.0  © 2001-2007 Comsenz Inc.