]> git.eli173.com Git - pong_br/commitdiff
communication works how I want it to! yay
authorElijah Cohen <eli@eli173.com>
Thu, 18 Apr 2019 15:32:55 +0000 (10:32 -0500)
committerElijah Cohen <eli@eli173.com>
Thu, 18 Apr 2019 15:32:55 +0000 (10:32 -0500)
server/game.js
server/player.js
web/test.js

index 1ea9ede113210adfedd346d7ab6111173751bb97..451aca790cb2afefa253a8f85c3d7916b0bede69 100644 (file)
@@ -8,13 +8,12 @@ function Game(players) {
 }
 
 Game.prototype.start = function(ms) {
-    var me = this;
-    var tmpfn = function() {me.getNextFrame()};
+    var _this = this;
+    var tmpfn = function() {_this.getNextFrame()};
     this.timeout = setInterval(tmpfn, ms);
 }
 
 Game.prototype.getNextFrame = function() {
-    console.log(this);
     var inputs = this.players.map(function(p) {return p.get_status();});
     this.state.update(inputs);
     var state = this.state.getState();
index 0c0767ed3ac8fa1ad32b44bf6b90ae95aa9badc4..48f0723b03480f800b2c2f9172327d37328cb300 100644 (file)
@@ -3,9 +3,14 @@
 function Player(ws) {
     this.status = 'x';
     this.socket = ws;
-    this.socket.onmessage = this.listener;
+    var _this = this;
+    var fn = function(msg) {
+       _this.listener(msg);
+    }
+    this.socket.onmessage = fn;
 }
 
+// this should probably be renamed...
 Player.prototype.listener = function(msg) {
     var data = msg.data;
     if(typeof data == "string" && data.length > 0) {
index aabbe0e9dfd652b72362b5e43e8d46ea194bb943..311bfb465f89f799b94abecd48578f517a253bce 100644 (file)
@@ -6,7 +6,6 @@ theSocket = null;
 
 function send(k, s) {
     // sends key k thru socket s
-    console.log(k);
     theSocket.send(k);
 }