Skip to content

Commit c127dd5

Browse files
committed
Merge pull request #1 from rbirkby/unusedcode
Remove unused syntax
2 parents 5d93c3c + a844e74 commit c127dd5

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

index.html

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!DOCTYPE html>
1+
<!DOCTYPE html>
22
<html>
33
<head>
44
<title>Javascript Tetris</title>
@@ -22,9 +22,9 @@
2222
@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 */
2323
@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 */
2424
</style>
25-
</head>
25+
</head>
2626

27-
<body>
27+
<body>
2828

2929
<div id="tetris">
3030
<div id="menu">
@@ -45,20 +45,20 @@
4545
// base helper methods
4646
//-------------------------------------------------------------------------
4747

48-
function get(id) { return document.getElementById(id); };
49-
function hide(id) { get(id).style.visibility = 'hidden'; };
50-
function show(id) { get(id).style.visibility = null; };
51-
function html(id, html) { get(id).innerHTML = html; };
48+
function get(id) { return document.getElementById(id); }
49+
function hide(id) { get(id).style.visibility = 'hidden'; }
50+
function show(id) { get(id).style.visibility = null; }
51+
function html(id, html) { get(id).innerHTML = html; }
5252

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

5757
if (!window.requestAnimationFrame) { // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
58-
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
59-
window.mozRequestAnimationFrame ||
60-
window.oRequestAnimationFrame ||
61-
window.msRequestAnimationFrame ||
58+
window.requestAnimationFrame = window.webkitRequestAnimationFrame ||
59+
window.mozRequestAnimationFrame ||
60+
window.oRequestAnimationFrame ||
61+
window.msRequestAnimationFrame ||
6262
function(callback, element) {
6363
window.setTimeout(callback, 1000 / 60);
6464
}
@@ -112,13 +112,13 @@
112112
//
113113
//-------------------------------------------------------------------------
114114

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

123123
//------------------------------------------------
124124
// do the bit manipulation and iterate through each
@@ -135,7 +135,7 @@
135135
++row;
136136
}
137137
}
138-
};
138+
}
139139

140140
//-----------------------------------------------------
141141
// check if a piece can fit into a position in the grid
@@ -147,11 +147,11 @@
147147
result = true;
148148
});
149149
return result;
150-
};
150+
}
151151

152152
function unoccupied(type, x, y, dir) {
153153
return !occupied(type, x, y, dir);
154-
};
154+
}
155155

156156
//-----------------------------------------
157157
// start with 4 instances of each piece and
@@ -163,7 +163,7 @@
163163
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];
164164
var type = pieces.splice(random(0, pieces.length-1), 1)[0];
165165
return { type: type, dir: DIR.UP, x: Math.round(random(0, nx - type.size)), y: 0 };
166-
};
166+
}
167167

168168

169169
//-------------------------------------------------------------------------
@@ -189,17 +189,17 @@
189189
reset(); // reset the per-game variables
190190
frame(); // start the first frame
191191

192-
};
192+
}
193193

194194
function showStats() {
195195
stats.domElement.id = 'stats';
196196
get('menu').appendChild(stats.domElement);
197-
};
197+
}
198198

199199
function addEvents() {
200200
document.addEventListener('keydown', keydown, false);
201201
window.addEventListener('resize', resize, false);
202-
};
202+
}
203203

204204
function resize(event) {
205205
canvas.width = canvas.clientWidth; // set canvas logical size equal to its physical size
@@ -210,7 +210,7 @@
210210
dy = canvas.height / ny; // (ditto)
211211
invalidate();
212212
invalidateNext();
213-
};
213+
}
214214

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

234234
//-------------------------------------------------------------------------
235235
// GAME LOGIC
236236
//-------------------------------------------------------------------------
237237

238-
function play() { hide('start'); reset(); playing = true; };
239-
function lose() { show('start'); setVisualScore(); playing = false; };
240-
241-
function setVisualScore(n) { vscore = n || score; invalidateScore(); };
242-
function setScore(n) { score = n; setVisualScore(n); };
243-
function addScore(n) { score = score + n; };
244-
function clearScore() { setScore(0); };
245-
function clearRows() { setRows(0); };
246-
function setRows(n) { rows = n; step = Math.max(speed.min, speed.start - (speed.decrement*rows)); invalidateRows(); };
247-
function addRows(n) { setRows(rows + n); };
248-
function getBlock(x,y) { return (blocks && blocks[x] ? blocks[x][y] : null); };
249-
function setBlock(x,y,type) { blocks[x] = blocks[x] || []; blocks[x][y] = type; invalidate(); };
238+
function play() { hide('start'); reset(); playing = true; }
239+
function lose() { show('start'); setVisualScore(); playing = false; }
240+
241+
function setVisualScore(n) { vscore = n || score; invalidateScore(); }
242+
function setScore(n) { score = n; setVisualScore(n); }
243+
function addScore(n) { score = score + n; }
244+
function clearScore() { setScore(0); }
245+
function clearRows() { setRows(0); }
246+
function setRows(n) { rows = n; step = Math.max(speed.min, speed.start - (speed.decrement*rows)); invalidateRows(); }
247+
function addRows(n) { setRows(rows + n); }
248+
function getBlock(x,y) { return (blocks && blocks[x] ? blocks[x][y] : null); }
249+
function setBlock(x,y,type) { blocks[x] = blocks[x] || []; blocks[x][y] = type; invalidate(); }
250250
function clearBlocks() { blocks = []; invalidate(); }
251-
function clearActions() { actions = []; };
252-
function setCurrentPiece(piece) { current = piece || randomPiece(); invalidate(); };
253-
function setNextPiece(piece) { next = piece || randomPiece(); invalidateNext(); };
251+
function clearActions() { actions = []; }
252+
function setCurrentPiece(piece) { current = piece || randomPiece(); invalidate(); }
253+
function setNextPiece(piece) { next = piece || randomPiece(); invalidateNext(); }
254254

255255
function reset() {
256256
dt = 0;
@@ -260,7 +260,7 @@
260260
clearScore();
261261
setCurrentPiece(next);
262262
setNextPiece();
263-
};
263+
}
264264

265265
function update(idt) {
266266
if (playing) {
@@ -271,9 +271,9 @@
271271
if (dt > step) {
272272
dt = dt - step;
273273
drop();
274-
}
274+
}
275275
}
276-
};
276+
}
277277

278278
function handle(action) {
279279
switch(action) {
@@ -282,7 +282,7 @@
282282
case DIR.UP: rotate(); break;
283283
case DIR.DOWN: drop(); break;
284284
}
285-
};
285+
}
286286

287287
function move(dir) {
288288
var x = current.x, y = current.y;
@@ -300,15 +300,15 @@
300300
else {
301301
return false;
302302
}
303-
};
303+
}
304304

305-
function rotate(dir) {
305+
function rotate() {
306306
var newdir = (current.dir == DIR.MAX ? DIR.MIN : current.dir + 1);
307307
if (unoccupied(current.type, current.x, current.y, newdir)) {
308308
current.dir = newdir;
309309
invalidate();
310310
}
311-
};
311+
}
312312

313313
function drop() {
314314
if (!move(DIR.DOWN)) {
@@ -322,13 +322,13 @@
322322
lose();
323323
}
324324
}
325-
};
325+
}
326326

327327
function dropPiece() {
328328
eachblock(current.type, current.x, current.y, current.dir, function(x, y) {
329329
setBlock(x, y, current.type);
330330
});
331-
};
331+
}
332332

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

353353
function removeLine(n) {
354354
var x, y;
355355
for(y = n ; y >= 0 ; --y) {
356356
for(x = 0 ; x < nx ; ++x)
357357
setBlock(x, y, (y == 0) ? null : getBlock(x, y-1));
358358
}
359-
};
359+
}
360360

361361
//-------------------------------------------------------------------------
362362
// RENDERING
@@ -378,7 +378,7 @@
378378
drawScore();
379379
drawRows();
380380
ctx.restore();
381-
};
381+
}
382382

383383
function drawCourt() {
384384
if (invalid.court) {
@@ -395,7 +395,7 @@
395395
ctx.strokeRect(0, 0, nx*dx - 1, ny*dy - 1); // court boundary
396396
invalid.court = false;
397397
}
398-
};
398+
}
399399

400400
function drawNext() {
401401
if (invalid.next) {
@@ -409,33 +409,33 @@
409409
uctx.restore();
410410
invalid.next = false;
411411
}
412-
};
412+
}
413413

414414
function drawScore() {
415415
if (invalid.score) {
416416
html('score', ("00000" + Math.floor(vscore)).slice(-5));
417417
invalid.score = false;
418418
}
419-
};
419+
}
420420

421421
function drawRows() {
422422
if (invalid.rows) {
423423
html('rows', rows);
424424
invalid.rows = false;
425425
}
426-
};
426+
}
427427

428428
function drawPiece(ctx, type, x, y, dir) {
429429
eachblock(type, x, y, dir, function(x, y) {
430430
drawBlock(ctx, x, y, type.color);
431431
});
432-
};
432+
}
433433

434434
function drawBlock(ctx, x, y, color) {
435435
ctx.fillStyle = color;
436436
ctx.fillRect(x*dx, y*dy, dx, dy);
437437
ctx.strokeRect(x*dx, y*dy, dx, dy)
438-
};
438+
}
439439

440440
//-------------------------------------------------------------------------
441441
// FINALLY, lets run the game
@@ -445,5 +445,5 @@
445445

446446
</script>
447447

448-
</body>
448+
</body>
449449
</html>

0 commit comments

Comments
 (0)