A game with one keyboard for 100+ players ! Each has a key and the only who press earns points.
function k(e){return e.keyCode}function u(e){var n=k(e);p[n]=false;t()}function n(e){var n=k(e);p[n]=true;t()}function t(){c.width=W;var e=0,t=[],n=g(p);for(var r in p){c.width+=32;if(r!=n){t.push([l[p[r]],y[r],r])}else{t.push([l["!"],y[r],r])}}for(var i=0;i<t.length;i++){if(t[i][0]){a.fillStyle=t[i][0]}a.fillRect(i*32,0,32,32);a.font="20px Arial";a.textBaseline="top";a.fillStyle="black";a.fillText(String.fromCharCode(t[i][2]),i*32+8,0);a.fillText(t[i][1],i*32+8,16,20)}}function g(e){var t=[];for(var n in e){if(e[n]){t.push(n)}if(!y[n]){y[n]=0}}if(t.length==1){y[t[0]]++;return t[0]}return false}var W=c.width=0,H=c.height=32,p={},y={},l={"true":"purple","false":"grey","!":"gold"},D=document.createElement("div");t();window.addEventListener("keydown",n);window.addEventListener("keyup",u);D.innerHTML="<div><strong>1Keyboard 100Friends</strong> - Play with your friends !<br/>Each has a key and the only who press earns points.<br/>Use your mental and physical skills!</div>";b.appendChild(D)
ZnVuY3Rpb24gayhlKXtyZXR1cm4gZS5rZXlDb2RlfWZ1bmN0aW9uIHUoZSl7dmFyIG49ayhlKTtwW25dPWZhbHNlO3QoKX1mdW5jdGlvbiBuKGUpe3ZhciBuPWsoZSk7cFtuXT10cnVlO3QoKX1mdW5jdGlvbiB0KCl7Yy53aWR0aD1XO3ZhciBlPTAsdD1bXSxuPWcocCk7Zm9yKHZhciByIGluIHApe2Mud2lkdGgrPTMyO2lmKHIhPW4pe3QucHVzaChbbFtwW3JdXSx5W3JdLHJdKX1lbHNle3QucHVzaChbbFsiISJdLHlbcl0scl0pfX1mb3IodmFyIGk9MDtpPHQubGVuZ3RoO2krKyl7aWYodFtpXVswXSl7YS5maWxsU3R5bGU9dFtpXVswXX1hLmZpbGxSZWN0KGkqMzIsMCwzMiwzMik7YS5mb250PSIyMHB4IEFyaWFsIjthLnRleHRCYXNlbGluZT0idG9wIjthLmZpbGxTdHlsZT0iYmxhY2siO2EuZmlsbFRleHQoU3RyaW5nLmZyb21DaGFyQ29kZSh0W2ldWzJdKSxpKjMyKzgsMCk7YS5maWxsVGV4dCh0W2ldWzFdLGkqMzIrOCwxNiwyMCl9fWZ1bmN0aW9uIGcoZSl7dmFyIHQ9W107Zm9yKHZhciBuIGluIGUpe2lmKGVbbl0pe3QucHVzaChuKX1pZigheVtuXSl7eVtuXT0wfX1pZih0Lmxlbmd0aD09MSl7eVt0WzBdXSsrO3JldHVybiB0WzBdfXJldHVybiBmYWxzZX12YXIgVz1jLndpZHRoPTAsSD1jLmhlaWdodD0zMixwPXt9LHk9e30sbD17InRydWUiOiJwdXJwbGUiLCJmYWxzZSI6ImdyZXkiLCIhIjoiZ29sZCJ9LEQ9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgiZGl2Iik7dCgpO3dpbmRvdy5hZGRFdmVudExpc3RlbmVyKCJrZXlkb3duIixuKTt3aW5kb3cuYWRkRXZlbnRMaXN0ZW5lcigia2V5dXAiLHUpO0QuaW5uZXJIVE1MPSI8ZGl2PjxzdHJvbmc+MUtleWJvYXJkIDEwMEZyaWVuZHM8L3N0cm9uZz4gLSBQbGF5IHdpdGggeW91ciBmcmllbmRzICE8YnIvPkVhY2ggaGFzIGEga2V5IGFuZCB0aGUgb25seSB3aG8gcHJlc3MgZWFybnMgcG9pbnRzLjxici8+VXNlIHlvdXIgbWVudGFsIGFuZCBwaHlzaWNhbCBza2lsbHMhPC9kaXY+IjtiLmFwcGVuZENoaWxkKEQp
// Welcome in my js1k program ! :D
//some var declarations
var W = c.width = 0, H = c.height = 32,p = {}, y = {}, l={"true":"purple","false":"grey","!":"gold"},D = document.createElement("div");
function k(e) // return the key pressed
{
return e.keyCode;
}
function u(e) // when a key is unpressed
{
var s = k(e);
p[s]=false;
t();
}
function n(e) // wen a key is pressed
{
var s = k(e);
p[s]=true;
t();
}
function t() // visual render
{
c.width = W;
var j = 0, d = [],q = g(p);
for(var i in p)
{
c.width += 32;
if(i != q)
{
d.push([ l[p[i]],y[i],i ]);
}
else
{
d.push( [ l['!'], y[i],i ]);
}
}
for(var h=0; h < d.length; h++)
{
if(d[h][0])
{
a.fillStyle = d[h][0];
}
a.fillRect(h*32,0,32,32);
a.font = "20px Arial";
a.textBaseline = "top";
a.fillStyle = "black";
a.fillText(String.fromCharCode((d[h][2])),h*32+8,0);
a.fillText(d[h][1],h*32+8,16,20);
}
}
function g(p) // calculate the score
{
var r = [];
for(var i in p)
{
if(p[i])
{
r.push(i);
}
if(!y[i])
{
y[i]=0;
}
}
if(r.length == 1)
{
y[r[0]]++;
return r[0];
}
return false;
}
t(); // start
window.addEventListener("keydown",n); // key press event
window.addEventListener("keyup",u);// key unpressed event
// show game description and rules
D.innerHTML = "<div><strong>1Keyboard 100Friends</strong> - Play with your friends !<br/>Each has a key and the only who press earns points.<br/>Use your mental and physical skills!</div>";
b.appendChild(D);