-
-
Save tmpvar/427237 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) | |
{ | |
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