Created
June 9, 2010 17:02
-
-
Save NakedMoleRatScientist/431807 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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