Skip to content

Instantly share code, notes, and snippets.

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