summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortomsmeding <hallo@tomsmeding.nl>2015-12-15 18:21:14 +0100
committertomsmeding <hallo@tomsmeding.nl>2015-12-15 18:21:14 +0100
commit9129c730de97b5180daf1670eaccb0dee21a2831 (patch)
treee48a80910ad4cf664946f307ed3c1d18ce9492bf
parent4d0edc8188f72d5aea187cc65e62af587cefe884 (diff)
Better ball sizes
-rw-r--r--index.html33
1 files changed, 26 insertions, 7 deletions
diff --git a/index.html b/index.html
index 97934e5..fee1f66 100644
--- a/index.html
+++ b/index.html
@@ -9,6 +9,15 @@
"use strict";
var SOUND_ON=location.hostname!="localhost"&&location.hostname!="127.0.0.1";
+var STORAGE_ON=true;
+try {
+ if(localStorage){
+ localStorage.setItem("___test",1);
+ localStorage.removeItem("___test");
+ } else STORAGE_ON=false;
+} catch(e){
+ STORAGE_ON=false;
+}
var COLOURS=["#00F","#F00","#0CC"];
@@ -31,20 +40,18 @@ socket.on("roomgameturn",roomgameturn);
socket.on("roomgameplace",roomgameplace);
socket.on("roomgamewin",roomgamewin);
-if(location.hostname=="localhost"&&Math.random()<.25){
- try{localStorage.setItem("nickname","aaa");}
- catch(e){}
+if(STORAGE_ON&&location.hostname=="localhost"&&Math.random()<.25){
+ localStorage.setItem("nickname","aaa");
}
-if(localStorage.getItem("nickname"))socket.emit("setnick",localStorage.getItem("nickname"));
+if(STORAGE_ON&&localStorage.getItem("nickname"))socket.emit("setnick",localStorage.getItem("nickname"));
else socket.emit("me",updateme);
socket.emit("userlist",updateuserlist);
function updateme(_me){
me=_me;
document.getElementById("nickname").innerHTML=me[1];
- try{localStorage.setItem("nickname",me[1]);}
- catch(e){}
+ if(STORAGE_ON)localStorage.setItem("nickname",me[1]);
}
function updateuserlist(_ul){
@@ -320,6 +327,14 @@ function dodestroyroom(roomid){
socket.emit("roomdestroy",roomid);
}
+function numneighbours(x,y){
+ if(x==0||x==W-1){
+ if(y==0||y==H-1)return 2;
+ else return 3;
+ } else if(y==0||y==H-1)return 3;
+ else return 4;
+}
+
function drawboard(ctx,cellsz,bd,clr,lastplacepos){
var x,y,i,angle,radius,ballradius;
ctx.clearRect(0,0,W*cellsz+1,H*cellsz+1);
@@ -351,7 +366,11 @@ function drawboard(ctx,cellsz,bd,clr,lastplacepos){
case 2: radius=.15; break;
default: radius=.2; break;
}
- ballradius=cellsz*(0.1+bd[y][x].n*.05);
+ switch(numneighbours(x,y)-bd[y][x].n){
+ case 3: ballradius=.15*cellsz; break;
+ case 2: ballradius=.18*cellsz; break;
+ default: ballradius=.22*cellsz; break;
+ }
for(i=0;i<bd[y][x].n;i++){
ctx.beginPath();
ctx.arc(