From 3485ff4a3e746f432e74a624a7ea42d66ffc211e Mon Sep 17 00:00:00 2001 From: "Glitch (hello-express)" Date: Tue, 17 Mar 2020 14:39:38 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9C=E2=9B=B3=EF=B8=8F=20Checkpoint=20.?= =?UTF-8?q?/server.js:9949330/609?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/server.js b/server.js index a7e30ed..deb5d73 100644 --- a/server.js +++ b/server.js @@ -1,4 +1,4 @@ -var http = require("http"); +const http = require("http"); http .createServer(function(request, response) { @@ -13,6 +13,7 @@ console.log("HTTP Host Established"); const MPPClient = require('mpp-client-xt'); const client = new MPPClient("http://www.multiplayerpiano.com", undefined); +const fs = require('fs'); client.start(); @@ -65,15 +66,17 @@ client.on("a", (msg) => { } break; case "dvd!stats": - chat("Edge hits: " + edgehits + " | Corner hits: " + cornerhits); + chat("Edge hits: " + stats.edgehits + " | Corner hits: " + stats.cornerhits); break; } }); var pos = {x: (Math.random() * 100) - 50, y: (Math.random() * 100) - 50}; var vel = {x: 2/5, y: 2/7}; -var cornerhits = 0; -var edgehits = 0; +var stats = { + cornerhits: 0, + edgehits: 0 +} var cursor = setInterval(function() { client.sendArray([{m:'m', x: client.getOwnParticipant().x = pos.x + 50, y: client.getOwnParticipant().y = pos.y + 50}]); @@ -97,16 +100,22 @@ var cursorupdate = setInterval(function() { vel.y = -vel.y; } if ((pos.x >= 50) && (pos.y >= 50)) { - cornerhits += 1; + stats.cornerhits += 1; } else if ((pos.x >= 50) && (pos.y <= -50)) { - cornerhits += 1; + stats.cornerhits += 1; } else if ((pos.x <= -50) && (pos.y <= -50)) { - cornerhits += 1; + stats.cornerhits += 1; } else if ((pos.x <= -50) && (pos.y >= 50)) { - cornerhits += 1; + stats.cornerhits += 1; } else if ((pos.x >= 50) || (pos.y >= 50) || (pos.y <= -50) || (pos.x <= -50)) { - edgehits += 1; + stats.edgehits += 1; } break; + fs.writeFile("stats.json", JSON.stringify(stats), { + if (err) { + console.log("stats.json couldn't be saved!"); + return console.log(err); + } + }); } }, 25);