var drawOverlay = function(ctx, place) {
ctx.save();
//ctx.font = what should it equal? mind sizes on mobile
- ctx.setTransform(1,0,0,1,0,0);
+ ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2);
ctx.fillStyle = 'rgba(225,225,225,100)'
- var string1 = "you placed: " + place;
- var string2 = "click or press =g= to play again"
- ctx.fillText(string1, 0, 100);
- ctx.fillText(string2, 0, 200); // magic number...
+ ctx.textAlign = 'center';
+ ctx.fillText("you placed: " + place, 0, -7.5);
+ ctx.fillText("press =g= or click", 0, 0); // magic numbers...
+ ctx.fillText("to play again", 0, 7.5);
ctx.restore();
}
-
+
+var drawWaiting = function(ctx) {
+ ctx.save();
+ ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2);
+ // i think that the above is unneccesary, but might as well be safe. Not like much is going on client-side
+ ctx.fillStyle = 'rgba(225,225,225,100)';
+ ctx.textAlign = 'center';
+ ctx.fillText("waiting for", 0, -5);
+ ctx.fillText("opponents...", 0, 5);
+ ctx.restore();
+}
+
+var drawOver = function(ctx) {
+ ctx.save();
+ ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2);
+ ctx.fillStyle = 'rgba(225,225,225,100)'
+ ctx.textAlign = 'center';
+ ctx.fillText("press =g= or click", 0, -5);
+ ctx.fillText("to play again", 0, 5);
+ ctx.restore();
+
+}
+
+var drawBusy = function(ctx) {
+ clearCanvas(ctx);
+ ctx.save();
+ ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2);
+ // i think that the above is unneccesary, but might as well be safe. Not like much is going on client-side
+ ctx.fillStyle = 'rgba(225,225,225,100)';
+ ctx.textAlign = 'center';
+ ctx.fillText("server is too busy now", 0, -7.5);
+ ctx.fillText("press =g= or click", 0, 0); // magic numbers...
+ ctx.fillText("to play again", 0, 7.5);
+ ctx.restore();
+
+}
var clearCanvas = function(ctx) {
ctx.save();
canvas.height = window.innerHeight;
ctx = canvas.getContext('2d');
// i need to modify the 10's here to be appropriate given the scaling of the window
- ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2); // change to setTransform?
+ ctx.setTransform(10, 0, 0, 10, ctx.canvas.width/2, ctx.canvas.height/2);
ctx.lineWidth = ctx.lineWidth/5;
- // this is just to have everything go easily for testing
+ // this is just to have everything go easily for testing, delete before final
+ /**
var othersockets = [];
for(var i=0; i<c.NUM_PLAYERS -1; i++) {
othersockets.push(new WebSocket(prefixurl));
}
-
+ /**/
theSocket = new WebSocket(prefixurl);
+ drawWaiting(ctx);
+
theSocket.onmessage = function(e) {
if(e.data == "busy") {
- onBusy();
+ canvas.onclick = function(e) {location.reload()} // okay, outside of 'input' file...
+ canvas.onkeydown = function(e) {if(e.keyCode == '71') location.reload()};
+ drawBusy(ctx);
+ // socket should be closed by server
return;
}
canvas.width = window.innerWidth;
theSocket.onclose = function(e) {clearInterval(interval)};
}
-var onBusy = function() {
- console.log("busy, try again later");
-}
window.addEventListener("DOMContentLoaded", e => main());