Skip to content

Instantly share code, notes, and snippets.

@knewter
Forked from NakedMoleRatScientist/score_network.js
Created June 10, 2010 17:29
Show Gist options
  • Save knewter/433325 to your computer and use it in GitHub Desktop.
Save knewter/433325 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");
};
}; // you need a semicolon here because the statement is self.initialize = something; something just happens to be an inline function.
//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