Skip to content

Instantly share code, notes, and snippets.

@tmpvar
Forked from NakedMoleRatScientist/score_network.js
Created June 6, 2010 02:51
Show Gist options
  • Save tmpvar/427237 to your computer and use it in GitHub Desktop.
Save tmpvar/427237 to your computer and use it in GitHub Desktop.
function ScoreNetwork(score)
{
this.ws = null;
this.data = null;
this.score = score;
this.initialize = function()
{
this.ws = new WebSocket('ws://localhost:7000');
this.ws.onmessage = function(event)
{
this.data = JSON.parse(event.data);
this.score.changeMinimum(this.getLimit());
};
this.ws.onclose = function()
{
console.log("Welcome to our world");
};
};
//Return the mininum score to submit score to database.
this.getLimit = function()
{
if (this.data.status === true)
{
return this.data.scores[99];
}
return false;
};
this.transmitScore = function()
{
var message =
{
name : "kiba",
points : this.score.points
};
this.ws.send(JSON.parse(message));
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment