Avatar billede Slettet bruger
19. november 2001 - 09:12 Der er 3 kommentarer og
2 løsninger

Tetris

Er der nogen der ved hvor der er en toturial, sourcecode eller andet der har noget med tetris spillet at gøre???

Eller er der nogen der vil programmere Tetris for mig? Jeg kan ikke give nogen løn eller noget men vi kan altid finde ud af et eller andet eller evt noget reklame på mit site...

Men kig på: http://www.friserverplads.dk/gamepulz/tetris/

Problemet med den gamle tetris version er at det lakker på gamle computere og nogle nyerer!
Avatar billede Slettet bruger
19. november 2001 - 09:14 #1
Eller evt i java! Men så skal det være open source!
Avatar billede lingoman Nybegynder
19. november 2001 - 09:20 #2
Jeg er da frisk på at lave en ny udgave, men spørgsmålet hører til under kategorien Job/opgaver: Freelance
mvh geo
Avatar billede NanoQ Nybegynder
19. november 2001 - 09:23 #3
Check denne: http://www.dansteinman.com/dynduo/demos/tetris/

Lavet i 100% javascript

Hele scriptet har du her:

<HTML>
<HEAD>
<!--
JavaScript Tetris
Written by Dan Steinman (dynduo@dansteinman.com)
Copyright 1997-1998

Deployed on 03/22/98
Last Updated on 03/22/98

Please do no redistribute this game.
Consult me before you use any code or graphics.
-->
<TITLE>JavaScript Tetris</TITLE>
<SCRIPT LANGUAGE=\"JavaScript\">
<!--

n = (document.layers) ? 1:0
ie = (document.all) ? 1:0

img = new Array(\"blank\",\"blue\",\"lblue\",\"red\",\"orange\",\"green\",\"yellow\",\"purple\",\"grey\",\"blank\",\"sblue\",\"slblue\",\"sred\",\"sorange\",\"sgreen\",\"syellow\",\"spurple\")
for (var i=0;i<img.length;i++) {
eval(img[i]+\"=new Image()\")
eval(img[i]+\".src=\'\"+img[i]+\".gif\'\")
eval(\"s\"+img[i]+\"=new Image()\")
eval(\"s\"+img[i]+\".src=\'s\"+img[i]+\".gif\'\")
}

b = new Array()
for (var i=0;i<=25;i++) {
    b[i] = new Array()
    for (var j=0;j<16;j++) {
        b[i][j] = 0
    }
}
for (var i=0;i<=25;i++) {
    b[i][0] = 1
    b[i][1] = 1
    b[i][14] = 1
    b[i][15] = 1
}
for (var j=0;j<=15;j++) {
    b[0][j] = 1
    b[1][j] = 1
    b[23][j] = 1
    b[24][j] = 1
    b[25][j] = 1
}

shape = new Array()
shapenew = new Array()
for (var i=0;i<=3;i++) {
    shape[i] = new Array
    shapenew[i] = new Array
    for (var j=0;j<=3;j++) {
        shape[i][j] = 0
        shapenew[i][j] = 0
    }
}
shape.type = 1
shape.color = lblue
nextshape = Math.ceil(9*Math.random())
if (nextshape==1) nextshapecolor = \"lblue\"
else if (nextshape==2) nextshapecolor = \"blue\"
else if (nextshape==3) nextshapecolor = \"yellow\"
else if (nextshape==4) nextshapecolor = \"orange\"
else if (nextshape==5 || nextshape==6) nextshapecolor = \"purple\"
else if (nextshape==7 || nextshape==8) nextshapecolor = \"green\"
else if (nextshape==9) nextshapecolor = \"red\"

leftactive = 0
rightactive = 0
score = 0

function init() {
    board = new dynLayer(\"boardDiv\",\"boardAreaDiv\")
    pc = new dynLayer(\"pcDiv\",\"boardAreaDiv\")
    pc.xp = Math.floor(pc.x/15)+2
    pc.yp = Math.floor(pc.y/15)+4
    nextpc = new dynLayer(\"nextpcDiv\",\"nextpcArea\")
    changePiece()
    shownon(\"links\")
    document.onkeydown = keyDown
    document.onkeyup = keyUp
    if (n) document.captureEvents(Event.KEYDOWN | Event.KEYUP)
}

gameplaying = 0
function startGame() {
    if (!gameplaying) {
    gameplaying = 1
    playMusic1()
    pc.show()
    nextpc.show()
    downactive = 1
    down()
    }
}

function stopGame() {
    if (gameplaying) {
    gameplaying = 0
    snapXactive = 0
    snapYactive = 0
    leftactive = 0
    rightactive = 0
    downactive = 0
    plantactive = 0
    planted = 0
    lefthold = 0
    righthold = 0
    leftpause = 0
    rightpause = 0
    pc.hide()
    nextpc.hide()
    xsnapped = 1
    ysnapped = 1
    level = 0
    levelSpeed()
    lines = 0
    score = 0
    displayScore()
    pc.x = 60
    pc.css.left = pc.x
    pc.y = -30
    pc.css.top = pc.y
    pc.xp = Math.floor(pc.x/15)+2
    pc.yp = Math.floor(pc.y/15)+4
    stopMusic()
    if (topmost<22) {
    for (var i=2;i<=22;i++) {
        for (var j=2;j<=13;j++) {
            b[i][j] = 0
            eval(\"board.ref.images[\'b\"+i+\"_\"+j+\"\'].src = grey.src\")
        }
    }
    }
    topmost = 22
    for (var i=0;i<=3;i++) {
        for (var j=0;j<=2;j++) {
            shape[i][j] = 0
            pc.ref.images[\'pc\'+i+\'_\'+j].src = blank.src
            nextpc.ref.images[\'nextpc\'+i+\'_\'+j].src = blank.src
        }
    }
    changePiece()
    if (startagain) {
        setTimeout(\"startGame()\",500)
    }
    else {
    }
    }
}

function quitGame() {
    if (gameplaying) {
    if (confirm(\"Do you want to play again?\")) startagain = 1
    else startagain = 0
    stopGame()
    }
}

level = 0
lines = 0
direction = \'left\'
function keyDown(e) {
    if (n) var nKey = e.which
    if (ie) var ieKey = window.event.keyCode
    if (nKey==52 || nKey==98 || ieKey==100 || ieKey==66) { // 4 or b
        lefthold = 1
        if (!leftpause && !leftactive) {
        snapXactive = 0
        rightactive = 0
        leftactive = 1
        direction = \'left\'
        pc.xp = Math.floor((pc.x)/15)+2
        left()
        }
    }
    else if (nKey==53 || nKey==110 || ieKey==101 || ieKey==78) { // 5 or n
        levelSpeedUp()
    }
    else if (nKey==54 || nKey==109 || ieKey==102 || ieKey==77) { // 6 or m
        righthold = 1
        if (!rightpause && !rightactive) {
        snapXactive = 0
        leftactive = 0
        rightactive = 1
        direction = \'right\'
        pc.xp = Math.ceil((pc.x)/15)+2
        right()
        }
    }
    else if (nKey==99 || ieKey==67) rotatePiece(\'left\') // c
    else if (nKey==118 || nKey==32 || nKey==48 || ieKey==86 || ieKey==32 || ieKey==96) rotatePiece(\'right\') // space or v or space or 0
    else if (nKey==113 || ieKey==81) {  //Q
        quitGame()
    }
}

lefthold = 0
leftactive = 0
leftpause = 0
righthold = 0
rightactive = 0
rightpause = 0
function keyUp(e) {
    if (n) var nKey = e.which
    if (ie) var ieKey = window.event.keyCode
    if (nKey==52 || nKey==98 || ieKey==100 || ieKey==66) { // 4 or b
        lefthold = 0
        if (!leftpause) {
        leftactive = 0
        if (righthold && !rightactive) {
            snapXactive = 0
            rightactive = 1
            direction = \'right\'
            pc.xp = Math.ceil((pc.x)/15)+2
            right()
        }
        else {
            if (!xsnapped && !snapXactive) {
                snapXactive = 1
                snapX(-5)
            }
        }
        }
    }
    else if (nKey==53 || nKey==110 || ieKey==101 || ieKey==78) { // 5 or n
        levelSpeed()
    }
    else if (nKey==54 || nKey==109 || ieKey==102 || ieKey==77) { // 6 or m
        righthold = 0
        if (!rightpause) {
        rightactive = 0
        if (lefthold && !leftactive) {
            snapXactive = 0
            leftactive = 1
            direction = \'left\'
            pc.xp = Math.floor((pc.x)/15)+2
            left()
        }
        else {
            if (!xsnapped && !snapXactive) {
                snapXactive = 1
                snapX(5)
            }
        }
        }
    }
}

function levelSpeed() {
    if (level==0) {yinc=5;yspeed=240;xinc=5;xspeed=50}
    else if (level==1) {yinc=5;yspeed=220;xinc=5;xspeed=50}
    else if (level==2) {yinc=5;yspeed=200;xinc=5;xspeed=45}
    else if (level==3) {yinc=5;yspeed=180;xinc=5;xspeed=45}
    else if (level==4) {yinc=5;yspeed=160;xinc=5;xspeed=40}
    else if (level==5) {yinc=5;yspeed=140;xinc=5;xspeed=40}
    else if (level==6) {yinc=5;yspeed=120;xinc=5;xspeed=35}
    else if (level==7) {yinc=5;yspeed=100;xinc=5;xspeed=35}
    else if (level==8) {yinc=5;yspeed=80;xinc=5;xspeed=30}
    else if (level==9) {yinc=5;yspeed=60;xinc=5;xspeed=25}
    else if (level==10) {yinc=5;yspeed=40;xinc=5;xspeed=20}
    else if (level==11) {yinc=5;yspeed=20;xinc=5;xspeed=15}
    else if (level==12) {yinc=5;yspeed=10;xinc=5;xspeed=10}
    else if (level==13) {yinc=15;yspeed=100;xinc=15;xspeed=120}
    else if (level==14) {yinc=15;yspeed=90;xinc=15;xspeed=100}
    else if (level==15) {yinc=15;yspeed=80;xinc=15;xspeed=80}
    else if (level==16) {yinc=15;yspeed=70;xinc=15;xspeed=60}
    else if (level==17) {yinc=15;yspeed=60;xinc=15;xspeed=50}
    else if (level==18) {yinc=15;yspeed=50;xinc=15;xspeed=40}
    else if (level==19) {yinc=15;yspeed=40;xinc=15;xspeed=25}
    else if (level==20) {yinc=15;yspeed=35;xinc=15;xspeed=10}
    else if (level==21) {yinc=15;yspeed=30;xinc=15}
    else if (level==22) {yinc=15;yspeed=25;xinc=15}
    else if (level==23) {yinc=15;yspeed=20;xinc=15}
    else if (level==24) {yinc=15;yspeed=15;xinc=15}
    else if (level==25) {yinc=15;yspeed=10;xinc=15}
}
function levelSpeedUp() {
    if (level==0) {yinc=10;yspeed=50}
    else if (level==1) {yinc=10;yspeed=40}
    else if (level==2) {yinc=10;yspeed=30}
    else if (level==3) {yinc=10;yspeed=20}
    else if (level==4) {yinc=10;yspeed=10}
    else if (level==5) {yinc=15;yspeed=70}
    else if (level==6) {yinc=15;yspeed=65}
    else if (level==7) {yinc=15;yspeed=60}
    else if (level==8) {yinc=15;yspeed=55}
    else if (level==9) {yinc=15;yspeed=50}
    else if (level==10) {yinc=15;yspeed=45}
    else if (level==11) {yinc=15;yspeed=40}
    else if (level==12) {yinc=15;yspeed=35}
    else if (level==13) {yinc=15;yspeed=30}
    else if (level==14) {yinc=15;yspeed=20}
    else if (level>=15) {yinc=15;yspeed=10}
}

yinc=5
yspeed=240
xinc=5
xspeed=36

xsnapped = 1
ysnapped = 1
function move(inc) {
    if (inc < 0) pc.xp = Math.floor((pc.x+inc)/15)+2
    else pc.xp = Math.ceil((pc.x+inc)/15)+2
    pc.x += inc
    pc.css.left = pc.x
    if (pc.x/15==Math.floor(pc.x/15)) xsnapped = 1
    else xsnapped = 0
}

function left() {
    if (leftactive) {
        if ((check(shape,-1,0) && (ysnapped || (!ysnapped && check(shape,-1,1))))  ) {
            move(-1*xinc)
            cancelPlant()
        }
        else if (!xsnapped && !snapXactive) {
            snapXactive = 1
            snapX(-5)
        }
        if (lefthold) setTimeout(\"left()\",xspeed)
        else leftactive = 0
    }
}

function right() {
    if (rightactive) {
        var xtemp = (xsnapped) ? 1:2
        if ((check(shape,xtemp,0) && (ysnapped || (!ysnapped && check(shape,xtemp,1)))) ) {
            move(xinc)
            cancelPlant()
        }
        else if (!xsnapped && !snapXactive) {
            snapXactive = 1
            snapX(5)
        }
        if (righthold) setTimeout(\"right()\",xspeed)
        else rightactive = 0
    }
}

snapXactive = 0
function snapX(inc) {
    if (snapXactive && !xsnapped) {
        move(inc)
        setTimeout(\"snapX(\"+inc+\")\",20)
    }
    else {
        snapXactive = 0
        cancelPlant()
    }
}

snapYactive = 0
function snapY() {
    if (snapYactive && !ysnapped) {
        pc.yp = Math.floor((pc.y+5)/15)+4
        pc.y += 5
        pc.css.top = pc.y
        if (pc.y/15==Math.floor(pc.y/15)) ysnapped = 1
        else {
            ysnapped = 0
            setTimeout(\"snapY()\",20)
        }
    }
    else {
        snapYactive = 0
    }
}

downactive = 0
plantactive = 0
planted = 0
dcount=0
function down() {
    if (downactive) {
        if (ysnapped) var vert = 1
        else var vert = 2
        if ((xsnapped && check(shape,0,vert)) || (!xsnapped && check(shape,0,vert) && (direction==\'left\'&&check(shape,1,vert) || (direction==\'right\'&&check(shape,-1,vert)) ) ) ) {
            pc.yp = Math.floor((pc.y+yinc)/15)+4
            pc.y += yinc
            pc.css.top = pc.y
            if (pc.y/15==Math.floor(pc.y/15)) ysnapped = 1
            else ysnapped = 0
            setTimeout(\"down()\",yspeed)
        }
        else if (!plantactive && !planted) {
            snapYactive = 1
            snapY()
            xinc = 5
            downactive = 0
            plantactive = 1
            planttimer = setTimeout(\"checkPlantPiece()\",250)
        }
        else downactive = 0
    }
}

function cancelPlant() {
    if (plantactive && !downactive && xsnapped && check(shape,0,1)) {
        clearTimeout(planttimer)
        if (level>=8 && level<=17) xinc = 10
        if (level>=18) xinc = 15
        plantactive = 0
        downactive = 1
        down()
    }
}

function checkPlantPiece() {
    downactive = 0
    setTimeout(\"plantPiece()\",Math.max(xspeed,yspeed))
}

topmost = 22
function plantPiece() {
    if (check(shape,0,1)) {
        plantactive = 0
        downactive = 1
        down()
    }
    else {
    planted = 1
    leftactive = 0
    rightactive = 0
    leftpause = 1
    rightpause = 1
    plantactive = 0

    for (var i=0;i<=3;i++)
    for (var j=0;j<=3;j++)
    if (shape[i][j]) {
        b[pc.yp+i][pc.xp+j] = 1
        board.ref.images[\"b\"+(pc.yp+i)+\"_\"+(pc.xp+j)].src = shape.color.src
    }

    var pieceline = (shape.type==9) ? 1:0

    pc.yp = Math.floor(pc.y/15)+4
    topmost = Math.min(topmost,pc.yp)

    line0 = 0
    for (var j=2;j<=13;j++) if (b[pc.yp][j]) line0++
    line0 = (line0==12) ? 1:0

    line1 = 0
    for (var j=2;j<=13;j++) if (b[pc.yp+1][j]) line1++
    line1 = (line1==12) ? 1:0

    line2 = 0
    if (pc.yp <= 20) {
    for (var j=2;j<=13;j++) if (b[pc.yp+2][j]) line2++
    line2 = (line2==12) ? 1:0
    }

    line3 = 0
    if (pieceline && pc.yp <= 19) {
    for (var j=2;j<=13;j++) if (b[pc.yp+3][j]) line3++
    line3 = (line3==12) ? 1:0
    }

    pc.hide()
    changePiece()
   
    newscore = line0+line1+line2+line3
    if (newscore==1) score+=100
    else if (newscore==2) score+=250
    else if (newscore==3) score+=400
    else if (newscore==4) score+=1000
   
    if (n && newscore==4) shake()
    else clearPiece()
    }
}

function clearPiece() {
    if (newscore==4) {
        for (var i=pc.yp+4;i>=topmost;i--) {
        for (var j=2;j<=13;j++) {
            b[i][j] = b[i-4][j]
            eval(\"board.ref.images[\'b\"+i+\"_\"+j+\"\'].src = board.ref.images[\'b\"+(i-4)+\"_\"+j+\"\'].src\")
        }
        }
        topmost+=4
    }
    else if (newscore>0) {
        for (var k=0;k<=3;k++) {
            if (eval(\"line\"+k)) {
                for (var i=pc.yp;i>=topmost-3;i--) {
                for (var j=2;j<=13;j++) {
                    b[i+k][j] = b[i+k-1][j]
                    eval(\"board.ref.images[\'b\"+(i+k)+\"_\"+j+\"\'].src = board.ref.images[\'b\"+(i+k-1)+\"_\"+j+\"\'].src\")
                }
                }
                topmost+=1
            }
        }
    }

    lines += newscore
    level = Math.floor(lines/10)
    levelSpeed()
    displayScore()
    planted = 0
    setTimeout(\"nextPiece()\",30)
}

function nextPiece() {
    if (topmost<=3) {
        pc.hide()
        if (confirm(\"Game Over\\n\\nDo you want to play again?\")) {
            startagain=1
            stopGame()
        }
        else {
            startagain = 0
            stopGame()
        }
    }
    else {
        pc.x = 60
        pc.css.left = pc.x
        pc.y = -30
        pc.css.top = pc.y
        pc.xp = Math.floor(pc.x/15)+2
        pc.yp = Math.floor(pc.y/15)+4
        leftpause = 0
        rightpause = 0
        pc.show()
        downactive = 1
        down()
        if (lefthold) {leftactive=1;left()}
        if (righthold) {rightactive=1;right()}
    }
}

shakecount = 0
function shake() {
    if (shakecount<=7) {
        if (shakecount==0) window.moveBy(5,0)
        else if (shakecount==1) window.moveBy(-7,6)
        else if (shakecount==2) window.moveBy(7,0)
        else if (shakecount==3) window.moveBy(-5,-6)
        else if (shakecount==4) window.moveBy(7,0)
        else if (shakecount==5) window.moveBy(-5,7)
        else if (shakecount==6) window.moveBy(5,0)
        else if (shakecount==7) window.moveBy(-7,-7)
        shakecount++
        setTimeout(\"shake()\",30)
    }
    else {
        shakecount=0
        setTimeout(\"clearPiece()\",30)
    }
}


function check(piece,x,y) {
    pc.xp = Math.floor(pc.x/15)+2
    pc.yp = Math.floor(pc.y/15)+4
    var stop = 0
    for (var i=0;i<4;i++)
    for (var j=0;j<4;j++)
    if (b[pc.yp+y+j][pc.xp+x+i] && piece[j][i]) {
        stop=1
        break
    }
    if (stop) return false
    else return true
}

function changePiece() {
    for (var i=0;i<=3;i++) {
        for (var j=0;j<=3;j++) {
            shape[i][j] = 0
            pc.ref.images[\'pc\'+i+\'_\'+j].src = blank.src
            nextpc.ref.images[\'nextpc\'+i+\'_\'+j].src = blank.src
        }
    }
    shape.type = nextshape
    shape.color = eval(nextshapecolor)

    nextshape = Math.ceil(9*Math.random())
    if (nextshape==1) changeNextPieceImages(\"lblue\",0,0,0,1,0,2,1,0)
    else if (nextshape==2) changeNextPieceImages(\"blue\",0,0,0,1,0,2,1,2)
    else if (nextshape==3) changeNextPieceImages(\"yellow\",0,1,0,2,1,0,1,1)
    else if (nextshape==4) changeNextPieceImages(\"orange\",0,0,0,1,1,1,1,2)
    else if (nextshape==5 || nextshape==6) changeNextPieceImages(\"purple\",0,0,0,1,0,2,1,1)
    else if (nextshape==7 || nextshape==8) changeNextPieceImages(\"green\",0,1,0,2,1,1,1,2)
    else if (nextshape==9) changeNextPieceImages(\"red\",1,0,1,1,1,2,1,3)

    if (shape.type==1) changePieceImages(1,0,1,1,1,2,2,0) // L right
    else if (shape.type==2) changePieceImages(1,0,1,1,1,2,2,2) // L left
    else if (shape.type==3) changePieceImages(0,1,0,2,1,0,1,1) // skew right
    else if (shape.type==4) changePieceImages(0,0,0,1,1,1,1,2) // skew left
    else if (shape.type==5 || shape.type==6) changePieceImages(1,0,1,1,1,2,2,1) // T
    else if (shape.type==7 || shape.type==8) changePieceImages(1,1,1,2,2,1,2,2) // square
    else if (shape.type==9) changePieceImages(1,0,1,1,1,2,1,3) // line
}

function changePieceImages(r1,c1,r2,c2,r3,c3,r4,c4) {
    shape[r1][c1] = 1
    shape[r2][c2] = 1
    shape[r3][c3] = 1
    shape[r4][c4] = 1
    pc.ref.images[\'pc\'+r1+\'_\'+c1].src = shape.color.src
    pc.ref.images[\'pc\'+r2+\'_\'+c2].src = shape.color.src
    pc.ref.images[\'pc\'+r3+\'_\'+c3].src = shape.color.src
    pc.ref.images[\'pc\'+r4+\'_\'+c4].src = shape.color.src
}

function changeNextPieceImages(color,r1,c1,r2,c2,r3,c3,r4,c4) {
    nextshapecolor = color
    nextpc.ref.images[\'nextpc\'+r1+\'_\'+c1].src = eval(\"s\"+nextshapecolor+\".src\")
    nextpc.ref.images[\'nextpc\'+r2+\'_\'+c2].src = eval(\"s\"+nextshapecolor+\".src\")
    nextpc.ref.images[\'nextpc\'+r3+\'_\'+c3].src = eval(\"s\"+nextshapecolor+\".src\")
    nextpc.ref.images[\'nextpc\'+r4+\'_\'+c4].src = eval(\"s\"+nextshapecolor+\".src\")
}

function rotatePiece(direction) {
    if (shape.type!=7 && shape.type!=8) {
    for (var i=0;i<=3;i++) {
        for (var j=0;j<=3;j++) {
            shapenew[i][j] = 0
        }
    }
    if (shape.type <= 6) {
        if (direction==\'left\') {
            for (var i=0;i<=2;i++)
            for (var j=0;j<=2;j++)
            shapenew[i][j] = shape[j][2-i]
        }
        else {
            for (var i=0;i<=2;i++)
            for (var j=0;j<=2;j++)
            shapenew[j][2-i] = shape[i][j]
        }
    }
    else if (shape.type >= 9) {
        if (direction==\'left\') {
            for (var i=0;i<=3;i++)
            for (var j=0;j<=3;j++)
            shapenew[i][j] = shape[j][3-i]
        }
        else {
            for (var i=0;i<=3;i++)
            for (var j=0;j<=3;j++)
            shapenew[j][3-i] = shape[i][j]
        }
    }
    if (ysnapped) var vert = 0
    else var vert = 1
    if ((xsnapped && check(shapenew,0,vert)) || (!xsnapped && check(shapenew,0,vert) && (direction==\'left\'&&check(shapenew,1,vert) || (direction==\'right\'&&check(shapenew,-1,vert)) ) ) ) {
        for (var i=0;i<=3;i++) {
            for (var j=0;j<=3;j++) {
                shape[i][j] = shapenew[i][j]
                if (shape[i][j] == 1) pc.ref.images[\'pc\'+i+\'_\'+j].src = shape.color.src
                else pc.ref.images[\'pc\'+i+\'_\'+j].src = blank.src
            }
        }
        cancelPlant()
        if (lefthold && !leftactive) {
            leftactive = 1
            left()
        }
        else if (righthold && !rightactive) {
            rightactive = 1
            right()
            }
        }
    }
}

function displayScore() {
    layerWrite(\"scoreDiv\",\"<SPAN>\"+score+\"</SPAN>\")
    layerWrite(\"linesDiv\",\"<SPAN>\"+lines+\"</SPAN>\")
}
function layerWrite(id,text) {
    if (n) {
        document.layers[\"scoreBoard\"].document.layers[id].document.write(text)
        document.layers[\"scoreBoard\"].document.layers[id].document.close()
    }
    else if (ie) document.all[id].innerHTML = text
}

function dynLayer(id,nestref) {
    if (n) {
        if (nestref) {
            this.css = eval(\"document.\" + nestref + \".document.\" + id)
            this.ref = eval(\"document.\" + nestref + \".document.\" + id + \".document\")
        }
        else {
            this.css = document.layers[id]
            this.ref = document.layers[id].document
        }
        this.x = this.css.left
        this.y = this.css.top
    }
    else if (ie) {
        this.css = document.all[id].style
        this.ref = document
        this.x = this.css.pixelLeft
        this.y = this.css.pixelTop
    }
    this.obj = id + \"Object\"
    eval(this.obj + \"=this\")
    this.moveBy = dynLayerMoveBy
    this.moveTo = dynLayerMoveTo
    this.show = dynLayerShow
    this.hide = dynLayerHide
}
function dynLayerMoveBy(x,y) {
    this.x += x
    this.css.left = this.x
    this.y += y
    this.css.top = this.y
}
function dynLayerMoveTo(x,y) {
    this.x = x
    this.css.left = this.x
    this.y = y
    this.css.top = this.y
}
function dynLayerShow() {
    if (n) this.css.visibility = \"show\"
    else if (ie) this.css.visibility = \"visible\"
}
function dynLayerHide() {
    if (n) this.css.visibility = \"hide\"
    else if (ie) this.css.visibility = \"hidden\"
}

if (n && navigator.platform==\"Win32\" && navigator.mimeTypes[\"audio/x-midi\"]) soundenabled = 1
else soundenabled = 0
musicon = 1
musictrack = 1

musictimeractive = 0
function playMusic1() {
    if (soundenabled && musicon) {
        stopMusic()
        musictrack = 1
        if (n) document.music1.play(true)
        if (ie) document.music1.run()
        musictimeractive = 1
        musictimer = setTimeout(\'playMusic2()\',137000)
    }
}
function playMusic2() {
    if (soundenabled && musicon) {
        stopMusic()
        musictrack = 2
        if (n) document.music2.play(true)
        if (ie) document.music2.run()
        musictimeractive = 1
        musictimer = setTimeout(\'playMusic1()\',151000)
    }
}
function stopMusic() {
    if (soundenabled) {
        if (musictimeractive) {
            clearTimeout(musictimer)
            musictimeractive = 0
        }
        document.music1.stop()
        document.music2.stop()
    }
}
function toggleMusic() {
    if (soundenabled) {
        if (musicon) {
            musicon = 0
            stopMusic()
        }
        else {
            musicon = 1
            if (gameplaying) {
                if (musictrack==1) playMusic1()
                else playMusic2()
            }
        }
    }
    else if (confirm(\"You do not have music capabilities.\\nYou require the multimedia addon for Netscape.\\n\\nDo you want to download it now?\")) blank.location = \"http://home.netscape.com/home/update.html\"
}

function swap(hideobj,showobj) {
    hidenon(hideobj)
    shownon(showobj)
}
function shownon(showobj) {
    if (n) document.layers[showobj].visibility = \"show\"
    else if (ie) document.all[showobj].style.visibility = \"visible\"
}
function hidenon(hideobj) {
    if (n) document.layers[hideobj].visibility = \"hide\"
    else if (ie) document.all[hideobj].style.visibility = \"hidden\"
}

//-->
</SCRIPT>
<STYLE TYPE=\"text/css\">
<!--
#title {position:absolute; left:240; top:10; width:180;}
#boardAreaDiv {position:absolute; left:25; top:25; width:180; height:285; clip:rect(0,180,285,0);}
#boardDiv {position:absolute; left:-30; top:-60; width:210; height:390}
#pcDiv {position:absolute; left:60; top:-30; width:60; height:60; clip:rect(0,60,60,0); visibility:hidden;}

A {color:#FFFFFF; font-family:Arial; font-size:10pt;}
SPAN {color:#C0C0C0; font-family:Arial; font-size:8pt;}
.score {color:#C0C0C0; font-family:Arial; font-size:9pt;}
.scorebold {color:#C0C0C0; font-family:Arial; font-size:9pt; font-weight:bold;}

#frame {position:absolute; left:10; top:10; width:210; height:315; clip:rect(0,210,315,0);}

#tbar {position:absolute; left:15; top:0; width:180;}
#bbar {position:absolute; left:15; top:300; width:180;}
#lbar {position:absolute; left:0; top:15; width:15;}
#rbar {position:absolute; left:195; top:15; width:15;}

#lt0 {position:absolute; left:0; top:0; width:15;}
#lt1 {position:absolute; left:15; top:0; width:15;}
#lt2 {position:absolute; left:0; top:15; width:15;}

#rt0 {position:absolute; left:195; top:0; width:15;}
#rt1 {position:absolute; left:180; top:0; width:15;}
#rt2 {position:absolute; left:195; top:15; width:15;}

#lb0 {position:absolute; left:0; top:300; width:15;}
#lb1 {position:absolute; left:15; top:300; width:15;}
#lb2 {position:absolute; left:0; top:285; width:15;}

#rb0 {position:absolute; left:195; top:300; width:15;}
#rb1 {position:absolute; left:180; top:300; width:15;}
#rb2 {position:absolute; left:195; top:285; width:15;}

#nextpcArea {position:absolute; left:235; top:55; width:110; height:85; clip:rect(0,110,85,0); background-color:#3E3E3E; layer-background-color:#3E3E3E;}
#nextpcDiv {position:absolute; left:35; top:40; width:40; height:40; clip:rect(0,40,40,0); visibility:hidden;}
#ntbar {position:absolute; left:15; top:0; width:80;}
#nbbar {position:absolute; left:15; top:70; width:80;}
#nlbar {position:absolute; left:0; top:15; width:15;}
#nrbar {position:absolute; left:95; top:15; width:15;}
#nlt {position:absolute; left:0; top:0; width:15;}
#nrt {position:absolute; left:95; top:0; width:15;}
#nlb {position:absolute; left:0; top:70; width:15;}
#nrb {position:absolute; left:95; top:70; width:15;}
#nextText {position:absolute; left:20; top:16; width:100;}

#scoreBoard {position:absolute; left:235; top:150; width:110; height:95; clip:rect(0,110,95,0); background-color:#3E3E3E; layer-background-color:#3E3E3E;}
#scoreText {position:absolute; left:20; top:15; width:70;}
#scoreDiv {position:absolute; left:20; top:30; width:70;}
#linesText {position:absolute; left:20; top:45; width:70;}
#linesDiv {position:absolute; left:20; top:60; width:70;}

#stbar {position:absolute; left:15; top:0; width:80;}
#sbbar {position:absolute; left:15; top:80; width:80;}
#slbar {position:absolute; left:0; top:15; width:15;}
#srbar {position:absolute; left:95; top:15; width:15;}
#slt {position:absolute; left:0; top:0; width:15;}
#srt {position:absolute; left:95; top:0; width:15;}
#slb {position:absolute; left:0; top:80; width:15;}
#srb {position:absolute; left:95; top:80; width:15;}

#links {position:absolute; left:250; top:250; width:300; visibility:hidden;}
#keys {position:absolute; left:250; top:250; width:300; visibility:hidden;}

-->
</STYLE>
</HEAD>

<BODY BGCOLOR=\"#000000\" onLoad=\"init()\">

<DIV ID=\"frame\">

<DIV ID=\"tbar\"><IMG SRC=\"bar-h.gif\" WIDTH=180 HEIGHT=15></DIV>
<DIV ID=\"bbar\"><IMG SRC=\"bar-h.gif\" WIDTH=180 HEIGHT=15></DIV>

<DIV ID=\"lbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=285></DIV>
<DIV ID=\"rbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=285></DIV>

<DIV ID=\"lt0\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"lt1\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"lt2\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>

<DIV ID=\"rt0\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"rt1\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"rt2\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>

<DIV ID=\"lb0\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"lb1\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"lb2\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>

<DIV ID=\"rb0\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"rb1\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"rb2\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
</DIV>

<DIV ID=\"nextpcArea\">
<DIV ID=\"nextpcDiv\">
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<SCRIPT LANGUAGE=\"JavaScript\">
for (var i=0;i<=3;i++) {
document.writeln(\'<TR>\')
for (var j=0;j<=3;j++) document.writeln(\'<TD><IMG NAME=\"nextpc\'+i+\'_\'+j+\'\" SRC=\"blank.gif\" WIDTH=10 HEIGHT=10></TD>\')
document.writeln(\'</TR>\')
}
</SCRIPT>
</TABLE>
</DIV>

<DIV ID=\"ntbar\"><IMG SRC=\"bar-h.gif\" WIDTH=80 HEIGHT=15></DIV>
<DIV ID=\"nbbar\"><IMG SRC=\"bar-h.gif\" WIDTH=80 HEIGHT=15></DIV>
<DIV ID=\"nlbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=55></DIV>
<DIV ID=\"nrbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=55></DIV>

<DIV ID=\"nlt\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"nrt\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"nlb\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"nrb\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>

<DIV ID=\"nextText\"><DIV CLASS=\"scorebold\">Next Piece:</DIV></DIV>
</DIV>

<DIV ID=\"title\"><IMG SRC=\"title.gif\" WIDTH=96 HEIGHT=40 BORDER=0 ALT=\"JavaScript Tetris\"></DIV>

<DIV ID=\"links\">
<A HREF=\"java script:startGame()\" onMouseOver=\"status=\'Start Game\';return true;\" onMouseOut=\"status=\'\'\">Start Game</A>
<BR><A HREF=\"java script:quitGame()\" onMouseOver=\"status=\'Quit Game\';return true;\" onMouseOut=\"status=\'\'\">Quit Game</A>
<BR><A HREF=\"java script:toggleMusic()\" onMouseOver=\"status=\'Music On/Off\';return true;\" onMouseOut=\"status=\'\'\">Music On/Off</A>
<BR><A HREF=\"java script:swap(\'links\',\'keys\')\" onMouseOver=\"status=\'Control Keys\';return true;\" onMouseOut=\"status=\'\'\">Control Keys</A>
</DIV>

<DIV ID=\"keys\">
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=300><TR><TD>
<SPAN CLASS=\"scorebold\">Control Keys:
</SPAN><BR><SPAN>Left: 4
<BR>Right: 6
<BR>Speed Drop: 5
<BR>Rotate CW: V,0(zero)
<BR>Rotate CCW: C
</SPAN><BR><A CLASS=\"small\" HREF=\"java script:swap(\'keys\',\'links\')\">okay</A></TD></TR></TABLE>
</DIV>

<DIV ID=\"scoreBoard\">
<DIV ID=\"scoreText\"><DIV CLASS=\"scorebold\">Score:</DIV></DIV>
<DIV ID=\"scoreDiv\"><SPAN>0</SPAN></DIV>
<DIV ID=\"linesText\"><DIV CLASS=\"scorebold\">Lines:</DIV></DIV>
<DIV ID=\"linesDiv\"><SPAN>0</SPAN></DIV>
<DIV ID=\"stbar\"><IMG SRC=\"bar-h.gif\" WIDTH=80 HEIGHT=15></DIV>
<DIV ID=\"sbbar\"><IMG SRC=\"bar-h.gif\" WIDTH=80 HEIGHT=15></DIV>
<DIV ID=\"slbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=80></DIV>
<DIV ID=\"srbar\"><IMG SRC=\"bar-v.gif\" WIDTH=15 HEIGHT=80></DIV>

<DIV ID=\"slt\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"srt\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"slb\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
<DIV ID=\"srb\"><IMG SRC=\"lgrey.gif\" WIDTH=15 HEIGHT=15></DIV>
</DIV>

<DIV ID=\"boardAreaDiv\">
<DIV ID=\"boardDiv\">
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<SCRIPT LANGUAGE=\"JavaScript\">
for (var i=0;i<=25;i++) {
document.writeln(\'<TR>\')
for (var j=0;j<=15;j++) document.writeln(\'<TD><IMG NAME=\"b\'+i+\'_\'+j+\'\" SRC=\"grey.gif\" WIDTH=15 HEIGHT=15></TD>\')
document.writeln(\'</TR>\')
}
</SCRIPT>
</TABLE>
</DIV>

<DIV ID=\"pcDiv\">
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0>
<SCRIPT LANGUAGE=\"JavaScript\">
for (var i=0;i<=3;i++) {
document.writeln(\'<TR>\')
for (var j=0;j<=3;j++) document.writeln(\'<TD><IMG NAME=\"pc\'+i+\'_\'+j+\'\" SRC=\"blank.gif\" WIDTH=15 HEIGHT=15></TD>\')
document.writeln(\'</TR>\')
}
</SCRIPT>
</TABLE>
</DIV>

</DIV>

<SCRIPT LANGUAGE=\"JavaScript\">
if (soundenabled) {
    document.write(\"<EMBED NAME=\'music1\' SRC=\'tetris1.mid\' LOOP=TRUE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>\")
    document.write(\"<EMBED NAME=\'music2\' SRC=\'tetris2.mid\' LOOP=TRUE AUTOSTART=FALSE HIDDEN=TRUE MASTERSOUND>\")
}
</SCRIPT>

</BODY>
</HTML>
Avatar billede NanoQ Nybegynder
19. november 2001 - 09:25 #4
se i det hele taget denne søgning: http://www.alltheweb.com/search?cat=web&lang=any&query=%2B%22javascript+tetris%22

(husk de fleste ikke vil have du ripper deres script... spørg om lov før du bruger det)

NanoQ
Avatar billede Slettet bruger
19. november 2001 - 17:08 #5
Se: http://www.eksperten.dk/spm/135822

Ellers tak for forsøget... Men begrundelsen for hvorfor at jeg ikke kunne bruge din version står her: http://www.eksperten.dk/spm/135822
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester