- Author:
- Frederick Polgardy
- Twitter:
- @
- GitHub:
- Facebook:
- Google+:
- +
- Reddit:
- /r/
- Pouet:
- Website:
- sustainablecode.tumblr.com
- Compo:
- classic
- Demo link:
- https://js1k.com/2010-first/demo/485
- Shortlink:
- https://js1k.com/485
- Blog post:
- please update here!
- Bytes:
- 1021
- Chars:
- 1021
- Submission
var d=document,e=d.body,h="childNodes",i="className";e.removeChild(e.children[0]);function j(a,b){var c=d.createElement(b);a.appendChild(c);return c}j(e,"style").innerHTML="h2{text-align:center}table{margin:auto}td{width:4px;height:4px;border:1px solid #444}td.b{!:#800}td.o{!:#00C}td:hover{!:#888}".replace(/!/g,"background");var k=j(e,"table"),l=j(e,"h2"),m=50,n=50,p=8,q=0;function r(){return Math.floor(Math.random()*m)}function s(a,b){for(var c=0;c<a;++c)b(c)}function t(){l.innerHTML=(p==0&&n>0?"LOSE.":p)+" : "+(n==0?"WIN!":n)}function u(a,b){x(a,b,-1,0);x(a,b,1,0);x(a,b,0,-1);x(a,b,0,1)}function x(a,b,c,v){++q;(function w(f,g){if(f<0||f>=m||g<0||g>=m){if(--q==0){--p;t()}}else{var o=k[h][g][h][f];if(o[i]=="o"){o[i]="";--n;t();--q;u(f,g,c,v)}else{o[i]="b";setTimeout(function(){o[i]="";c!=0?w(f+c,g):w(f,g+v)},25)}}})(a,b)}s(m,function(a){var b=j(k,"tr");s(m,function(c){j(b,"td").onclick=function(){p>0&&n>0&&q==0&&u(c,a)}})});s(n,function(){for(;;){var a=k[h][r()][h][r()];if(a[i]!="o"){a[i]="o";break}}});t()
- Description
- Clear away the blue squares by clicking anywhere on the board.
- Base64 encoded
dmFyIGQ9ZG9jdW1lbnQsZT1kLmJvZHksaD0iY2hpbGROb2RlcyIsaT0iY2xhc3NOYW1lIjtlLnJlbW92ZUNoaWxkKGUuY2hpbGRyZW5bMF0pO2Z1bmN0aW9uIGooYSxiKXt2YXIgYz1kLmNyZWF0ZUVsZW1lbnQoYik7YS5hcHBlbmRDaGlsZ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3Rpb24oKXtmb3IoOzspe3ZhciBhPWtbaF1bcigpXVtoXVtyKCldO2lmKGFbaV0hPSJvIil7YVtpXT0ibyI7YnJlYWt9fX0pO3QoKQ==
- Original source
var doc = document, body = doc.body, childNodes = 'childNodes', className = 'className';
body.removeChild(body.children[0]);
function appendTo(parent, tagName) {
var child = doc.createElement(tagName);
parent.appendChild(child);
return child;
}
appendTo(body, 'style').innerHTML = 'h2{text-align:center}table{margin:auto}td{width:4px;height:4px;border:1px solid #444}td.b{!:#800}td.o{!:#00C}td:hover{!:#888}'.replace(/!/g, 'background');
var board = appendTo(body, 'table');
var counter = appendTo(body, 'h2');
var size = 50, pieces = 50, moves = 8, bullets = 0;
function random() {
alert(0);
return Math.floor(Math.random() * size);
}
function range(n, iterator) {
for (var i = 0; i < n; ++i) iterator(i);
}
function updateStatus() {
counter.innerHTML = (moves == 0 && pieces > 0 ? 'LOSE.' : moves) + ' : ' + (pieces == 0 ? 'WIN!' : pieces);
}
function fireBullets(x, y, dx, dy) {
fireBullet(x, y, -1, 0);
fireBullet(x, y, 1, 0);
fireBullet(x, y, 0, -1);
fireBullet(x, y, 0, 1);
}
function fireBullet(x, y, dx, dy) {
++bullets;
(function moveBullet(x, y) {
if (x < 0 || x >= size || y < 0 || y >= size) {
if (--bullets == 0) {
--moves; updateStatus();
}
} else {
var cell = board[childNodes][y][childNodes][x];
if (cell[className] == 'o') {
cell[className] = '';
--pieces; updateStatus();
--bullets;
fireBullets(x, y, dx, dy);
} else {
cell[className] = 'b';
setTimeout(function () {
cell[className] = '';
if (dx != 0) moveBullet(x + dx, y);
else moveBullet(x, y + dy);
}, 25);
}
}
}(x, y));
}
range(size, function (y) {
var row = appendTo(board, 'tr');
range(size, function (x) {
appendTo(row, 'td').onclick = function () {
if (moves > 0 && pieces > 0 && bullets == 0) fireBullets(x, y);
};
});
});
range(pieces, function () {
for (;;) {
var cell = board[childNodes][random()][childNodes][random()];
if (cell[className] != 'o') {
cell[className] = 'o';
break;
}
}
});
updateStatus()