diff options
Diffstat (limited to 'public/js/game.js')
| -rw-r--r-- | public/js/game.js | 43 |
1 files changed, 33 insertions, 10 deletions
diff --git a/public/js/game.js b/public/js/game.js index 8aed496..78a4728 100644 --- a/public/js/game.js +++ b/public/js/game.js @@ -34,25 +34,28 @@ var Events = { // Player connects to the game welcome: function(data){ for (var i in data.messages) { - Chat.add(data.messages[i]); + Chat.add( data.messages[i] ); + } + for (var i in data.players) { + Roster.add( data.players[i] ); } }, // Another player joins the room join: function(data){ - Events.receive.state(data); + Roster.add( data ); }, // Another player leaves the room part: function(data){ - Events.receive.state(data); + Roster.remove( data ); }, // Game state changes state: function(data){ if (Game.state == data.state) return; UI[ States.current ].unload(); - UI[ data.state ].load(); + UI[ data.state ].load(data); Game.state = data.state; }, @@ -65,7 +68,9 @@ var Events = { image: function(data) { console.log(data); if (data.nick == Game.nick) return; - $("#image").attr("src", data.url).show(); + // preload the image + var img = new Image(); + img.src = data.url; }, // Another player votes on an image @@ -76,6 +81,11 @@ var Events = { send: { + // Joining the game + join: function(data) { + socket.emit('event-join', data); + }, + // Sending a message message: function(msg) { socket.emit('event-message', msg); @@ -94,35 +104,48 @@ var Events = { // Anything a load method does should be undone by the unload method.. for now. var UI = {}; UI[ State.WAITING ] = { - load: function(){ + load: function(data){ + $("#current-state").html("Waiting"); + $("#drawing").show(); }, unload: function(){ + $("#drawing").hide(); } } UI[ State.DRAWING ] = { - load: function(){ + load: function(data){ + $("#current-state").html("Draw!"); + $("#drawing").show(); }, unload: function(){ + $("#drawing").hide(); } } UI[ State.VOTING ] = { - load: function(){ + load: function(data){ + $("#current-state").html("Vote!"); + $("#voting").show(); }, unload: function(){ + $("#voting").hide(); } } UI[ State.WINNING ] = { - load: function(){ + load: function(data){ + $("#current-state").html("Win!"); + $("#winning").show(); }, unload: function(){ + $("#winning").hide(); } } UI[ State.RESET ] = { - load: function(){ + load: function(data){ + $("#current-state").html("whoahao RESET!"); }, unload: function(){ } |
