summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2013-03-05 03:24:00 -0500
committerJules Laplace <jules@okfoc.us>2013-03-05 03:24:00 -0500
commita45ae4e59de9d8d2934c233eb3decc300d9078bd (patch)
treef2e9f521b8331bbaa37861e6cb9acbae326e5274 /public/js
parentdba03a90555d9f8516551ddf2e1758c37ca60c25 (diff)
the word is ....
Diffstat (limited to 'public/js')
-rw-r--r--public/js/draw.js7
-rw-r--r--public/js/game.js22
2 files changed, 25 insertions, 4 deletions
diff --git a/public/js/draw.js b/public/js/draw.js
index 8bd82df..b969c1e 100644
--- a/public/js/draw.js
+++ b/public/js/draw.js
@@ -9,8 +9,8 @@ $(function(){
clearWorkspace();
- var offset = $(workspace).offset();
-
+ var offset;
+
$(workspace).mousedown(function(e){
drawing = true;
});
@@ -30,6 +30,9 @@ $(function(){
}
$("#chat-message").focus();
});
+ $(window).on("drawing:start", function(){
+ offset = $(workspace).offset();
+ });
function clearWorkspace(){
workspaceCtx.fillStyle = "#fff";
workspaceCtx.fillRect(0,0,workspace.width,workspace.height);
diff --git a/public/js/game.js b/public/js/game.js
index a4cf74b..0b90328 100644
--- a/public/js/game.js
+++ b/public/js/game.js
@@ -71,7 +71,7 @@ var Events = {
img.src = data.url;
},
- // Another player votes on an image
+ // Another player votes on an image..
vote: function(data){
}
@@ -116,8 +116,9 @@ UI[ State.WAITING ] = new function() {
UI[ State.DRAWING ] = new function(){
this.load = function(data){
- $("#current-state").html("Draw!");
+ $("#current-state").html("Draw! The word is " + data.word);
$("#drawing").show();
+ $(window).trigger("drawing:start")
},
this.unload = function(){
$("#drawing").hide();
@@ -149,13 +150,30 @@ UI[ State.VOTING ] = new function(){
this.click = function(){
voted = true;
var nick = $(this).data("nick");
+ console.log("VOTE >> ", nick);
Events.send.vote({ nick: nick });
}
}
UI[ State.WINNING ] = new function(){
+ this.build = function(data){
+ $("#winning").empty();
+ var scores = [];
+ for (var i in data.scores) {
+ scores.push( [data.scores[i], i] );
+ }
+ var topthree = scores.sort(function(){ a[0] - b[0] }).splice(0, 3);
+ for (var i in topthree) {
+ var score = topthree[i][0]
+ var nick = topthree[i][1]
+ var image = data.images[ nick ];
+ var $li = $("<li>");
+ $li.html("<img src='" + image.url + "'> " + image.nick );
+ }
+ }
this.load = function(data){
$("#current-state").html("Win!");
+ this.build(data);
$("#winning").show();
}
this.unload = function(){