Skip to content

Commit

Permalink
Merge pull request #1 from rbirkby/unusedcode
Browse files Browse the repository at this point in the history
Remove unused syntax
  • Loading branch information
jakesgordon committed Aug 16, 2014
2 parents 5d93c3c + a844e74 commit c127dd5
Showing 1 changed file with 64 additions and 64 deletions.
128 changes: 64 additions & 64 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!DOCTYPE html>
<html>
<head>
<title>Javascript Tetris</title>
Expand All @@ -22,9 +22,9 @@
@media screen and (min-width: 800px) and (min-height: 800px) { #tetris { font-size: 2.00em; width: 750px; } #menu { width: 350px; height: 700px; } #upcoming { width: 175px; height: 175px; } #canvas { width: 350px; height: 700px; } } /* 35px chunks */
@media screen and (min-width: 900px) and (min-height: 900px) { #tetris { font-size: 2.25em; width: 850px; } #menu { width: 400px; height: 800px; } #upcoming { width: 200px; height: 200px; } #canvas { width: 400px; height: 800px; } } /* 40px chunks */
</style>
</head>
</head>

<body>
<body>

<div id="tetris">
<div id="menu">
Expand All @@ -45,20 +45,20 @@
// base helper methods
//-------------------------------------------------------------------------

function get(id) { return document.getElementById(id); };
function hide(id) { get(id).style.visibility = 'hidden'; };
function show(id) { get(id).style.visibility = null; };
function html(id, html) { get(id).innerHTML = html; };
function get(id) { return document.getElementById(id); }
function hide(id) { get(id).style.visibility = 'hidden'; }
function show(id) { get(id).style.visibility = null; }
function html(id, html) { get(id).innerHTML = html; }

function timestamp() { return new Date().getTime(); };
function random(min, max) { return (min + (Math.random() * (max - min))); };
function randomChoice(choices) { return choices[Math.round(random(0, choices.length-1))]; };
function timestamp() { return new Date().getTime(); }
function random(min, max) { return (min + (Math.random() * (max - min))); }
function randomChoice(choices) { return choices[Math.round(random(0, choices.length-1))]; }

if (!window.requestAnimationFrame) { // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(callback, element) {
window.setTimeout(callback, 1000 / 60);
}
Expand Down Expand Up @@ -112,13 +112,13 @@
//
//-------------------------------------------------------------------------

var i = { id: 'i', size: 4, blocks: [0x0F00, 0x2222, 0x00F0, 0x4444], color: 'cyan' };
var j = { id: 'j', size: 3, blocks: [0x44C0, 0x8E00, 0x6440, 0x0E20], color: 'blue' };
var l = { id: 'l', size: 3, blocks: [0x4460, 0x0E80, 0xC440, 0x2E00], color: 'orange' };
var o = { id: 'o', size: 2, blocks: [0xCC00, 0xCC00, 0xCC00, 0xCC00], color: 'yellow' };
var s = { id: 's', size: 3, blocks: [0x06C0, 0x8C40, 0x6C00, 0x4620], color: 'green' };
var t = { id: 't', size: 3, blocks: [0x0E40, 0x4C40, 0x4E00, 0x4640], color: 'purple' };
var z = { id: 'z', size: 3, blocks: [0x0C60, 0x4C80, 0xC600, 0x2640], color: 'red' };
var i = { size: 4, blocks: [0x0F00, 0x2222, 0x00F0, 0x4444], color: 'cyan' };
var j = { size: 3, blocks: [0x44C0, 0x8E00, 0x6440, 0x0E20], color: 'blue' };
var l = { size: 3, blocks: [0x4460, 0x0E80, 0xC440, 0x2E00], color: 'orange' };
var o = { size: 2, blocks: [0xCC00, 0xCC00, 0xCC00, 0xCC00], color: 'yellow' };
var s = { size: 3, blocks: [0x06C0, 0x8C40, 0x6C00, 0x4620], color: 'green' };
var t = { size: 3, blocks: [0x0E40, 0x4C40, 0x4E00, 0x4640], color: 'purple' };
var z = { size: 3, blocks: [0x0C60, 0x4C80, 0xC600, 0x2640], color: 'red' };

//------------------------------------------------
// do the bit manipulation and iterate through each
Expand All @@ -135,7 +135,7 @@
++row;
}
}
};
}

//-----------------------------------------------------
// check if a piece can fit into a position in the grid
Expand All @@ -147,11 +147,11 @@
result = true;
});
return result;
};
}

function unoccupied(type, x, y, dir) {
return !occupied(type, x, y, dir);
};
}

//-----------------------------------------
// start with 4 instances of each piece and
Expand All @@ -163,7 +163,7 @@
pieces = [i,i,i,i,j,j,j,j,l,l,l,l,o,o,o,o,s,s,s,s,t,t,t,t,z,z,z,z];
var type = pieces.splice(random(0, pieces.length-1), 1)[0];
return { type: type, dir: DIR.UP, x: Math.round(random(0, nx - type.size)), y: 0 };
};
}


//-------------------------------------------------------------------------
Expand All @@ -189,17 +189,17 @@
reset(); // reset the per-game variables
frame(); // start the first frame

};
}

function showStats() {
stats.domElement.id = 'stats';
get('menu').appendChild(stats.domElement);
};
}

function addEvents() {
document.addEventListener('keydown', keydown, false);
window.addEventListener('resize', resize, false);
};
}

function resize(event) {
canvas.width = canvas.clientWidth; // set canvas logical size equal to its physical size
Expand All @@ -210,7 +210,7 @@
dy = canvas.height / ny; // (ditto)
invalidate();
invalidateNext();
};
}

function keydown(ev) {
var handled = false;
Expand All @@ -229,28 +229,28 @@
}
if (handled)
ev.preventDefault(); // prevent arrow keys from scrolling the page (supported in IE9+ and all other browsers)
};
}

//-------------------------------------------------------------------------
// GAME LOGIC
//-------------------------------------------------------------------------

function play() { hide('start'); reset(); playing = true; };
function lose() { show('start'); setVisualScore(); playing = false; };

function setVisualScore(n) { vscore = n || score; invalidateScore(); };
function setScore(n) { score = n; setVisualScore(n); };
function addScore(n) { score = score + n; };
function clearScore() { setScore(0); };
function clearRows() { setRows(0); };
function setRows(n) { rows = n; step = Math.max(speed.min, speed.start - (speed.decrement*rows)); invalidateRows(); };
function addRows(n) { setRows(rows + n); };
function getBlock(x,y) { return (blocks && blocks[x] ? blocks[x][y] : null); };
function setBlock(x,y,type) { blocks[x] = blocks[x] || []; blocks[x][y] = type; invalidate(); };
function play() { hide('start'); reset(); playing = true; }
function lose() { show('start'); setVisualScore(); playing = false; }

function setVisualScore(n) { vscore = n || score; invalidateScore(); }
function setScore(n) { score = n; setVisualScore(n); }
function addScore(n) { score = score + n; }
function clearScore() { setScore(0); }
function clearRows() { setRows(0); }
function setRows(n) { rows = n; step = Math.max(speed.min, speed.start - (speed.decrement*rows)); invalidateRows(); }
function addRows(n) { setRows(rows + n); }
function getBlock(x,y) { return (blocks && blocks[x] ? blocks[x][y] : null); }
function setBlock(x,y,type) { blocks[x] = blocks[x] || []; blocks[x][y] = type; invalidate(); }
function clearBlocks() { blocks = []; invalidate(); }
function clearActions() { actions = []; };
function setCurrentPiece(piece) { current = piece || randomPiece(); invalidate(); };
function setNextPiece(piece) { next = piece || randomPiece(); invalidateNext(); };
function clearActions() { actions = []; }
function setCurrentPiece(piece) { current = piece || randomPiece(); invalidate(); }
function setNextPiece(piece) { next = piece || randomPiece(); invalidateNext(); }

function reset() {
dt = 0;
Expand All @@ -260,7 +260,7 @@
clearScore();
setCurrentPiece(next);
setNextPiece();
};
}

function update(idt) {
if (playing) {
Expand All @@ -271,9 +271,9 @@
if (dt > step) {
dt = dt - step;
drop();
}
}
}
};
}

function handle(action) {
switch(action) {
Expand All @@ -282,7 +282,7 @@
case DIR.UP: rotate(); break;
case DIR.DOWN: drop(); break;
}
};
}

function move(dir) {
var x = current.x, y = current.y;
Expand All @@ -300,15 +300,15 @@
else {
return false;
}
};
}

function rotate(dir) {
function rotate() {
var newdir = (current.dir == DIR.MAX ? DIR.MIN : current.dir + 1);
if (unoccupied(current.type, current.x, current.y, newdir)) {
current.dir = newdir;
invalidate();
}
};
}

function drop() {
if (!move(DIR.DOWN)) {
Expand All @@ -322,13 +322,13 @@
lose();
}
}
};
}

function dropPiece() {
eachblock(current.type, current.x, current.y, current.dir, function(x, y) {
setBlock(x, y, current.type);
});
};
}

function removeLines() {
var x, y, complete, n = 0;
Expand All @@ -348,15 +348,15 @@
addRows(n);
addScore(100*Math.pow(2,n-1)); // 1: 100, 2: 200, 3: 400, 4: 800
}
};
}

function removeLine(n) {
var x, y;
for(y = n ; y >= 0 ; --y) {
for(x = 0 ; x < nx ; ++x)
setBlock(x, y, (y == 0) ? null : getBlock(x, y-1));
}
};
}

//-------------------------------------------------------------------------
// RENDERING
Expand All @@ -378,7 +378,7 @@
drawScore();
drawRows();
ctx.restore();
};
}

function drawCourt() {
if (invalid.court) {
Expand All @@ -395,7 +395,7 @@
ctx.strokeRect(0, 0, nx*dx - 1, ny*dy - 1); // court boundary
invalid.court = false;
}
};
}

function drawNext() {
if (invalid.next) {
Expand All @@ -409,33 +409,33 @@
uctx.restore();
invalid.next = false;
}
};
}

function drawScore() {
if (invalid.score) {
html('score', ("00000" + Math.floor(vscore)).slice(-5));
invalid.score = false;
}
};
}

function drawRows() {
if (invalid.rows) {
html('rows', rows);
invalid.rows = false;
}
};
}

function drawPiece(ctx, type, x, y, dir) {
eachblock(type, x, y, dir, function(x, y) {
drawBlock(ctx, x, y, type.color);
});
};
}

function drawBlock(ctx, x, y, color) {
ctx.fillStyle = color;
ctx.fillRect(x*dx, y*dy, dx, dy);
ctx.strokeRect(x*dx, y*dy, dx, dy)
};
}

//-------------------------------------------------------------------------
// FINALLY, lets run the game
Expand All @@ -445,5 +445,5 @@

</script>

</body>
</body>
</html>

1 comment on commit c127dd5

@MONIMAKER365
Copy link

@MONIMAKER365 MONIMAKER365 commented on c127dd5 Feb 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add file for update for pull request #1 index.html
Update license #30

Please sign in to comment.