-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshim.html
54 lines (51 loc) · 2.63 KB
/
shim.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!doctype html>
<html>
<head>
<title>JS1k, [COMPO] demo submission [ID]</title>
<meta charset="utf-8" />
<style>
html, body { margin: 0; padding: 0; border: 0; }
#c { display: block; } /* kill scrollbars from hell */
</style>
</head>
<body>
<canvas id="c"></canvas>
<script>
var a = document.getElementsByTagName('canvas')[0];
var b = document.body;
var d = function(e){ return function(){ e.parentNode.removeChild(e); }; }(a);
// unprefix some popular vendor prefixed things (but stick to their original name)
var AudioContext =
window.AudioContext ||
window.webkitAudioContext;
var requestAnimationFrame =
window.requestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(f){ setTimeout(f, 1000/30); };
// fix bug in safari: http://qfox.nl/weblog/218
document.body.clientWidth;
// auto resize (original) canvas. call `onresize(w,h) to limit the size of the canvas
(window.onorientationchange = window.onresize = function(a){
var mw = Infinity;
var mh = Infinity;
var min = Math.min;
return function(w,h){
if (arguments.length === 2) {
mw = w;
mh = h;
}
a.style.width = (a.width = min(mw, innerWidth)) + 'px';
a.style.height = (a.height = min(mh, innerHeight)) + 'px';
};
}(a))();
var c = a.getContext('2d');
</script>
<script>
// start of submission //
function l(){return Math.floor(Math.random()*a)}function k(b,h,k,l){++e,function m(b,h){if(b<0||b>=a||h<0||h>=a)--e||(--d,i());else{var n=t[f][0][f][h][f][b];n[g]=="o"?(n[g]="",--c,--e,i(),j(b,h)):(n[g]="b",setTimeout(function(){n[g]="",k!=0?m(b+k,h):m(b,h+l)},25))}}(b,h)}function j(a,b){k(a,b,-1,0),k(a,b,1,0),k(a,b,0,-1),k(a,b,0,1)}function i(){u.innerHTML=!d&&c?"You Lose!":c?"Moves: "+d+" — Pieces: "+c:"You Win!"}var a=50,c=50,d=8,e=0,f="children",g="className",h="parentNode";b.innerHTML='<style>body{background:#111;margin:10px;}h2{color:#EEE}table{border-collapse:collapse;border-spacing:0}td{border:1px solid #333;width:8px;height:8px}td:hover{background:#444}.b{background:#EEE}.o{background:#F80}</style><h2 id="u">Click Any Square To Play</h2><table id="t">'+Array(a+1).join("<tr>"+Array(a+1).join("<td></td>")+"</tr>")+"</table>",t.onclick=function(a){var b=a.target;d&&c&&!e&&j(b.cellIndex,b[h].rowIndex)};for(var m=0;m<c;++m)for(;;){var n=t[f][0][f][l()][f][l()];if(n[g]!="o"){n[g]="o";break}}
// end of submission //
</script>
</body>
</html>