<p><!--raw0Tag-->
<style>
#displaycontent {
margin-left:0px;
}
</style>
<!--/raw0Tag--><script type="text/javascript">
//new handler here
var tempscore;
var loadHandler=0;
var dispHandler=0;
function getHiScore(score) {
tempscore=score;
loadHandler=2;
document.getElementById("hiloader").src = 'http://dhgamescores.pbwiki.com/Dummy?aph=a092fc1790c8f7c59989a32cefa15118b57c325a';
}
function loadAuth() {
if (loadHandler==0) {
loadHandler=1;
document.getElementById("hiloader").src = 'http://dhgamescores.pbwiki.com/Dummy?aph=a092fc1790c8f7c59989a32cefa15118b57c325a';
}
else if (loadHandler==1) {
displayHandler=1;
document.getElementById("hidisplay").src = 'http://dhgamescores.pbwiki.com/SideBar?game=Tetris&raw=bare'
loadHandler=-1;
}
else if (loadHandler==2) {
loadHandler=3;
document.getElementById("hiloader").src = 'http://dhgamescores.pbwiki.com/FrontPage?game=Tetris&score=' + tempscore;
}
else if (loadHandler==3) {
loadHandler=1;
}
}
function loadDisp() {
if (dispHandler==1) {
document.getElementById("hiloader").src = 'http://dhgamescores.pbwiki.com/?logout=1';
loadHandler=-1;
}
}
</script><div style="float:left;padding:5px;width:120px;text-align:center">
<p> </p>
<p><div style="width:120px;text-align:right"><b>Speed:</b> <select id="selectSpeed" style="width:70px"><option value="">Select</option><option value="">0</option><option value="">1</option><option value="">2</option><option value="">3</option><option value="">4</option><option value="">5</option><option value="">6</option><option value="">7</option><option value="">8</option><option value="">9</option></select>
<p> </p>
<p><b>High:</b> <select id="selectHigh" style="width:70px"><option value="">Select</option><option value="">0</option><option value="">1</option><option value="">2</option><option value="">3</option><option value="">4</option><option value="">5</option></select></div>
<p> </p>
<p><input id="myButton" type="button" onclick="if (game) game.runGame();" value="Start" />
<p> </p>
<p><b>Controls</b>:
<p><em>Left/Right</em> - move
<p><em>Down</em> - drop faster
<p><em>Up</em> - rotate
<p><em>P</em> - pause
<p> </p>
<p><b>Alternate:</b>
<p><em>A/D</em> - left/right
<p><em>S</em> - down
<p><em>W</em> - rotate
<p> </p>
<p>(Alt. keys are for browsers that don't like using the arrow keys).
<p> </p>
<p></div><div id="field" style="float:left; width:200px; border:1px solid black; padding:5px; margin:5px"></div><div style="float:left;margin:5px;width:140px"><h2 style="margin-top:0px">Next:</h2>
<p> </p>
<p><div id="preview" style="margin-left:20px"></div>
<p> </p>
<h2>Score:</h2>
<p> </p>
<p><div id="myScore" style="color:green;width:140px;text-align:right;font-size:15pt;font-weight:bold;font-family:monospace">0</div>
<p> </p>
<h2>Speed:</h2>
<p> </p>
<p><div id="mySpeed" style="color:green;width:140px;text-align:right;font-size:15pt;font-weight:bold;font-family:monospace"><span style="color:red">GAME OVER</span></div>
<p> </p>
<h2>Lines:</h2>
<p> </p>
<p><div id="myLines" style="color:green;width:140px;text-align:right;font-size:15pt;font-weight:bold;font-family:monospace">0</div></div>
<p> </p>
<p><div style="margin:5px; float:left; width:250px;height:400px"><span id="bgplayer"></span><!--raw0Tag--><input type="button" value="Song 1" onclick="var mid = document.getElementById('bgplayer'); mid.innerHTML = '<embed autostart=true loop=true hidden=true src=/f/tetrisa.mid></embed>'" /> <input type="button" value="Song 2" onclick="var mid = document.getElementById('bgplayer'); mid.innerHTML = '<embed autostart=true loop=true hidden=true src=/f/tetrisb.mid></embed>'" /> <input type="button" value="Stop" onclick="var mid = document.getElementById('bgplayer'); mid.innerHTML = ''" /><!--/raw0Tag-->
<p> </p>
<p> </p>
<p><iframe id="hidisplay" src="" style="width:100%; height:300px" onload="loadDisp()"></iframe></div>
<p> </p>
<p> </p>
<p><iframe id="hiloader" src="Tetris?raw=1" style="width:10px;height:10px;position:absolute; visibility:hidden; top:0px; left:0px;" onload="loadAuth()"></iframe><br clear=left />
<p><hr align="left" class="wiki"/>
<p> </p>
<p><b>HINT</b>: You get bonuses for starting with more blocks on the screen and also for having a faster speed. So if you start at Speed 9, you'll get the speed bonus AND your speed won't change until you get 100 lines. If you can manage that AND have your "High" at 5, you'll get a lot of bonuses for each clear.
<p> </p>
<p>I don't know who in fact owns the Tetris copyright. I certainly don't, but I do own this code, so if you want to use it, ask me first, or in the least credit me somehow.
<p> </p>
<p><script type="text/javascript">
document.onkeypress = function() {return false;}
window.onload=null;
var sb = document.getElementById("SideBar");
if (sb) sb.style.display='none';
//note: (0,0) = bottom left
var colors = new Array("#000000","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#999999")
//square, z, reverse-z, line, L, reverse-L, T
var piece1 = new Array(new Array(0,0,0,1,1,0,1,1) , new Array(0,0,0,1,1,0,1,1) , new Array(0,0,0,1,1,0,1,1) , new Array(0,0,0,1,1,0,1,1));
var piece2 = new Array(new Array(0,1,1,1,1,0,2,0) , new Array(0,0,0,1,1,1,1,2) , new Array(0,1,1,1,1,0,2,0) , new Array(0,0,0,1,1,1,1,2));
var piece3 = new Array(new Array(0,0,1,0,1,1,2,1) , new Array(0,1,0,2,1,1,1,0) , new Array(0,0,1,0,1,1,2,1) , new Array(0,1,0,2,1,1,1,0));
var piece4 = new Array(new Array(0,-1,0,0,0,1,0,2) , new Array(-1,0,0,0,1,0,2,0) , new Array(0,-1,0,0,0,1,0,2) , new Array(-1,0,0,0,1,0,2,0));
var piece5 = new Array(new Array(0,0,0,1,0,2,1,0) , new Array(0,0,0,1,1,1,2,1) , new Array(0,2,1,2,1,1,1,0) , new Array(-1,0,0,0,1,0,1,1));
var piece6 = new Array(new Array(0,0,1,0,1,1,1,2) , new Array(0,0,0,1,1,0,2,0) , new Array(0,0,0,1,0,2,1,2) , new Array(-1,1,0,1,1,1,1,0));
var piece7 = new Array(new Array(0,0,1,0,1,1,2,0) , new Array(0,0,0,1,0,2,1,1) , new Array(0,1,1,1,1,0,2,1) , new Array(0,1,1,0,1,1,1,2));
var pieces = new Array(piece1, piece2, piece3, piece4, piece5, piece6, piece7);
function Tetris(obj) {
this.score = 0;
this.speed = 0; //how fast
this.level = 0; //how many rows to start
this.field = obj;
this.lines = 0;
this.inGame = false;
this.paused = false;
this.fieldArray = new Array();
this.dropBonus = 0;
this.high = 0;
for (var i=0; i<25; i++) {
this.fieldArray[i] = new Array();
for (var j=0; j<10 ; j++) {
this.fieldArray[i][j] = 0;
}
}
initField(obj);
initPrev(document.getElementById('preview'));
this.currentPiece = new tetrisPiece();
this.nextPiece = new tetrisPiece();
this.refresh = drawField; //redraws field
this.reset = reset; //resets arrays, numbers
this.runGame = runGame; //starts the game
this.drawPiece = drawPiece;
this.erasePiece = erasePiece;
this.putPiece = putPiece;
this.pieceOkay = pieceOkay;
this.checkField = checkField;
this.drawPreview = drawPreview;
this.erasePreview = erasePreview;
}
var tempGame;
var timer;
function runGame() {
clearTimeout(timer);
if (this.inGame) {
document.getElementById('mySpeed').innerHTML = '<span style="color:red">GAME OVER</span>';
document.getElementById("myButton").value="Start";
initPrev(document.getElementById('preview'));
this.reset();
this.inGame = false;
document.onkeydown = null;
window.onblur = null;
return;
}
document.onkeydown = handleKeys;
window.onblur = pauseOnBlur;
document.getElementById("myButton").value="Stop";
initPrev(document.getElementById('preview'));
this.reset();
this.inGame = true;
this.speed = document.getElementById("selectSpeed").selectedIndex;
if (this.speed!=0) this.speed--;
this.high = document.getElementById("selectHigh").selectedIndex;
if (this.high!=0) {
var h=this.high;
this.high--;
for (var i=0;i<(h-1)*2;i++) {
for (var j=0;j<this.fieldArray[0].length;j++) {
this.fieldArray[i][j] = Math.floor(Math.random()*7) + 1;
}
var blank = Math.floor(Math.random()*5) + 1;
for (var k=0;k<blank;k++) {
this.fieldArray[i][Math.floor(Math.random()*10)] = 0;
}
}
}
this.refresh();
document.getElementById('mySpeed').innerHTML = this.speed;
document.getElementById('myScore').innerHTML = this.score;
document.getElementById('myLines').innerHTML = this.lines;
this.drawPreview();
tempGame = this;
timer = window.setTimeout("dropPiece(tempGame)",speedToInterval(this.speed));
}
function speedToInterval(speed) {
return (16-speed) * 35;
}
function tetrisPiece() {
this.x = 4;
this.y = 21;
var pieceNum = Math.floor(Math.random()*7);
this.type = pieceNum + 1;
this.piece = pieces[pieceNum];
this.rotation = 0; //0-3
this.rotateR = rotateRight;
this.rotateL = rotateLeft;
}
function rotateRight() {
this.rotation++;
if (this.rotation==4) this.rotation=0;
}
function rotateLeft() {
this.rotation--;
if (this.rotation==-1) this.rotation=3;
}
function pieceOkay() {
//workin here
var temp = this.currentPiece;
for (var i=0;i<8;i+=2) {
var x = temp.x + temp.piece[temp.rotation][i];
var y = temp.y + temp.piece[temp.rotation][i+1];
if (y<0 || x<0 || x>=this.fieldArray[0].length) return false;
if (y<this.fieldArray.length) {
if (this.fieldArray[y][x]!=0) return false;
}
}
return true;
}
function dropPiece(game) {
if (!game.inGame || game.paused) return;
game.erasePiece();
game.currentPiece.y--;
if (!game.pieceOkay()) {
game.currentPiece.y++;
game.putPiece();
game.drawPiece();
game.checkField();
game.dropBonus = 0;
game.currentPiece = game.nextPiece;
game.erasePreview();
game.nextPiece = new tetrisPiece();
game.drawPreview();
if (game.inGame) document.getElementById('mySpeed').innerHTML = game.speed;
document.getElementById('myScore').innerHTML = game.score;
document.getElementById('myLines').innerHTML = game.lines;
}
game.drawPiece();
timer = window.setTimeout("dropPiece(tempGame)",speedToInterval(game.speed));
}
function putPiece() {
var temp = this.currentPiece;
for (var i=0;i<8;i+=2) {
var x = temp.x + temp.piece[temp.rotation][i];
var y = temp.y + temp.piece[temp.rotation][i+1];
if (y>=0 && x>=0 && x<this.fieldArray[0].length && y<this.fieldArray.length)
this.fieldArray[y][x] = temp.type;
}
}
var scoreBase = new Array(1,2,4,8)
function checkField() {
var total=0;
for (var i=this.fieldArray.length-1;i>=0;i--) {
var thisRow = 0;
for (var j=0; j<this.fieldArray[0].length;j++) {
if (this.fieldArray[i][j]!=0) thisRow++
}
if (i>=22 && thisRow!=0) {
//GAME OVER CODE HERE
getHiScore(this.score);
document.getElementById('mySpeed').innerHTML = '<span style="color:red">GAME OVER</span>';
document.getElementById("myButton").value="Start";
initPrev(document.getElementById('preview'));
this.inGame = false;
}
if (thisRow>=this.fieldArray[0].length) { //full line
total++;
for (var a=i+1;a<this.fieldArray.length;a++) { //shift from top down
for (var b=0;b<this.fieldArray[0].length;b++) {
this.fieldArray[a-1][b] = this.fieldArray[a][b];
}
}
for (var c=0;c<this.fieldArray[0].length;c++) {
this.fieldArray[this.fieldArray.length-1][c] = 0;
}
this.refresh();
}
}
if (total>0) {
if (parseInt(this.lines/10) != parseInt((this.lines+total)/10)) {
this.score += ((this.speed+1) * 1000)
if (this.speed<15 && this.speed<parseInt((this.lines+total)/10)) this.speed++;
}
this.score += (scoreBase[total-1] * 1000);
this.lines += total;
this.score += (this.high * 50 * total);
}
this.score += (this.dropBonus * 5);
}
function drawPreview() {
var temp = this.nextPiece;
for (var i=0;i<8;i+=2) {
var x = 1 + temp.piece[temp.rotation][i];
var y = 1 + temp.piece[temp.rotation][i+1];
if (document.getElementById('prev' + y + '_' + x))
document.getElementById('prev' + y + '_' + x).style.background = colors[temp.type]
}
}
function erasePreview() {
var temp = this.nextPiece;
for (var i=0;i<8;i+=2) {
var x = 1 + temp.piece[temp.rotation][i];
var y = 1 + temp.piece[temp.rotation][i+1];
if (document.getElementById('prev' + y + '_' + x))
document.getElementById('prev' + y + '_' + x).style.background = colors[0]
}
}
function drawPiece() {
var temp = this.currentPiece;
for (var i=0;i<8;i+=2) {
var x = temp.x + temp.piece[temp.rotation][i];
var y = temp.y + temp.piece[temp.rotation][i+1];
var tempE = document.getElementById(y + '_' + x);
if (tempE) {
tempE.style.background = colors[temp.type]
tempE.style.borderTop = "1px solid white";
tempE.style.borderLeft = "1px solid white";
tempE.style.borderRight = "1px solid black";
tempE.style.borderBottom = "1px solid black";
}
}
}
function erasePiece() {
var temp = this.currentPiece;
for (var i=0;i<8;i+=2) {
var x = temp.x + temp.piece[temp.rotation][i];
var y = temp.y + temp.piece[temp.rotation][i+1];
if (document.getElementById(y + '_' + x)) {
document.getElementById(y + '_' + x).style.background = colors[0];
document.getElementById(y + '_' + x).style.border = "1px solid " + colors[0];
}
}
}
function togglePause() {
if (tempGame.paused) {
tempGame.paused = false;
timer = window.setTimeout("dropPiece(tempGame)",speedToInterval(tempGame.speed));
document.getElementById('mySpeed').innerHTML = tempGame.speed;
}
else {
tempGame.paused = true;
document.getElementById('mySpeed').innerHTML = '<span style="color:red">PAUSED</span>';
}
}
function pauseOnBlur() {
if (!tempGame.inGame) return;
tempGame.paused = true;
document.getElementById('mySpeed').innerHTML = '<span style="color:red">PAUSED</span>';
}
function handleKeys(e) {
if (!tempGame.inGame) return false;
var keyID;
if (!e) e = window.event;
if (e.keyCode) keyID = e.keyCode;
else if (e.which) keyID = e.which;
// alert(keyID);
if (keyID==80) togglePause(); //p
if (tempGame.paused) return;
switch(keyID) {
case 37: //left
case 65: //a
tempGame.erasePiece();
tempGame.currentPiece.x--;
if (!tempGame.pieceOkay()) tempGame.currentPiece.x++;
tempGame.drawPiece();
break;
case 39: //right
case 68: //d
tempGame.erasePiece();
tempGame.currentPiece.x++;
if (!tempGame.pieceOkay()) tempGame.currentPiece.x--;
tempGame.drawPiece();
break;
case 83: //s
case 40: //down
tempGame.erasePiece();
tempGame.currentPiece.y--;
if (!tempGame.pieceOkay()) tempGame.currentPiece.y++;
else tempGame.dropBonus++;
tempGame.drawPiece();
break;
case 87: //w
case 38: //up
tempGame.erasePiece();
tempGame.currentPiece.rotateR();
if (!tempGame.pieceOkay()) tempGame.currentPiece.rotateL();
tempGame.drawPiece();
break;
}
return false;
}
function reset() {
for (var i=0; i<25; i++) {
for (var j=0; j<10 ; j++) {
this.fieldArray[i][j] = 0;
}
}
this.refresh();
this.score = 0;
this.speed = 0; //how fast
this.level = 0; //how many rows to start
this.lines = 0;
this.dropBonus = 0;
this.inGame = false;
this.currentPiece = new tetrisPiece();
this.nextPiece = new tetrisPiece();
this.paused = false;
}
function drawField() {
for (var a=0; a<20; a++) {
for (var b=0; b<10 ; b++) {
var tc = this.fieldArray[a][b]
document.getElementById(a + '_' + b).style.background = colors[tc];
if (tc==0) document.getElementById(a + '_' + b).style.border = "1px solid black";
else {
document.getElementById(a + '_' + b).style.borderTop = "1px solid white";
document.getElementById(a + '_' + b).style.borderLeft = "1px solid white";
document.getElementById(a + '_' + b).style.borderRight = "1px solid black";
document.getElementById(a + '_' + b).style.borderBottom = "1px solid black";
}
}
}
}
function initField(obj) {
var code = "";
for (var i=19; i>=0; i--) {
for (var j=0;j<10;j++) {
code += '<div id="' + i + '_' + j + '" style="float:left; width:18px; height:18px; border:1px solid black;background:black; "><!----></div>';
}
code += '<br clear=left />';
}
obj.innerHTML = code;
}
function initPrev(obj) {
var code = '';
for (var i=4; i>=0; i--) {
for (var j=0;j<5;j++) {
code += '<div id="prev' + i + '_' + j + '" style="float:left; width:18px; height:18px; border-left:1px solid #aaaaaa; border-top:1px solid #aaaaaa; border-right:1px solid #333333; border-bottom:1px solid #333333;background:black; font-size:1px"><!----></div>';
}
code += '<br clear=left />';
}
obj.innerHTML = code;
}
var game = new Tetris(document.getElementById('field'));
</script>
<p>
Comments ()
You don't have permission to comment on this page.