From 28636fa6a56f617bd494414ecf0adb4d7fb7fc03 Mon Sep 17 00:00:00 2001 From: Gary Weiss Date: Fri, 1 Feb 2019 11:31:01 +0200 Subject: [PATCH] cosmetic changes --- main.js | 8 +-- package-lock.json | 87 +++++++++++++++++++++++-------- src/server/SpaaaceServerEngine.js | 10 +++- 3 files changed, 76 insertions(+), 29 deletions(-) diff --git a/main.js b/main.js index ba9cf54..b84a183 100644 --- a/main.js +++ b/main.js @@ -15,13 +15,13 @@ let requestHandler = server.listen(PORT, () => console.log(`Listening on ${ PORT const io = socketIO(requestHandler); // Game Server -import MyServerEngine from './src/server/SpaaaceServerEngine.js'; -import MyGameEngine from './src/common/SpaaaceGameEngine.js'; +import SpaaaceServerEngine from './src/server/SpaaaceServerEngine.js'; +import SpaaaceGameEngine from './src/common/SpaaaceGameEngine.js'; // Game Instances -const gameEngine = new MyGameEngine({ traceLevel: 1000 }); -const serverEngine = new MyServerEngine(io, gameEngine, { +const gameEngine = new SpaaaceGameEngine({ traceLevel: 1000 }); +const serverEngine = new SpaaaceServerEngine(io, gameEngine, { debug: {}, updateRate: 6, timeoutInterval: 0 // no timeout diff --git a/package-lock.json b/package-lock.json index 658f749..b0e9e3e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1415,7 +1415,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -1433,11 +1434,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -1450,15 +1453,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -1561,7 +1567,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -1571,6 +1578,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -1583,17 +1591,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -1610,6 +1621,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -1682,7 +1694,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -1692,6 +1705,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -1767,7 +1781,8 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -1797,6 +1812,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -1814,6 +1830,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -1852,11 +1869,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.2", - "bundled": true + "bundled": true, + "optional": true } } } @@ -3272,6 +3291,7 @@ "version": "2.0.0", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-2.0.0.tgz", "integrity": "sha1-gTg9ctsFT8zPUzbaqQLxgvbtuyg=", + "optional": true, "requires": { "is-glob": "^2.0.0" } @@ -3708,7 +3728,8 @@ "is-extglob": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-1.0.0.tgz", - "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=" + "integrity": "sha1-rEaBd8SUNAWgkvyPKXYMb/xiBsA=", + "optional": true }, "is-finite": { "version": "1.0.2", @@ -3730,6 +3751,7 @@ "version": "2.0.1", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-2.0.1.tgz", "integrity": "sha1-0Jb5JqPe1WAPP9/ZEZjLCIjC2GM=", + "optional": true, "requires": { "is-extglob": "^1.0.0" } @@ -7768,7 +7790,8 @@ }, "ansi-regex": { "version": "2.1.1", - "bundled": true + "bundled": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -7786,11 +7809,13 @@ }, "balanced-match": { "version": "1.0.0", - "bundled": true + "bundled": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -7803,15 +7828,18 @@ }, "code-point-at": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "concat-map": { "version": "0.0.1", - "bundled": true + "bundled": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", - "bundled": true + "bundled": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -7914,7 +7942,8 @@ }, "inherits": { "version": "2.0.3", - "bundled": true + "bundled": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -7924,6 +7953,7 @@ "is-fullwidth-code-point": { "version": "1.0.0", "bundled": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -7936,17 +7966,20 @@ "minimatch": { "version": "3.0.4", "bundled": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } }, "minimist": { "version": "0.0.8", - "bundled": true + "bundled": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -7963,6 +7996,7 @@ "mkdirp": { "version": "0.5.1", "bundled": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -8035,7 +8069,8 @@ }, "number-is-nan": { "version": "1.0.1", - "bundled": true + "bundled": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -8045,6 +8080,7 @@ "once": { "version": "1.4.0", "bundled": true, + "optional": true, "requires": { "wrappy": "1" } @@ -8120,7 +8156,8 @@ }, "safe-buffer": { "version": "5.1.1", - "bundled": true + "bundled": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -8150,6 +8187,7 @@ "string-width": { "version": "1.0.2", "bundled": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -8167,6 +8205,7 @@ "strip-ansi": { "version": "3.0.1", "bundled": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -8205,11 +8244,13 @@ }, "wrappy": { "version": "1.0.2", - "bundled": true + "bundled": true, + "optional": true }, "yallist": { "version": "3.0.2", - "bundled": true + "bundled": true, + "optional": true } } }, diff --git a/src/server/SpaaaceServerEngine.js b/src/server/SpaaaceServerEngine.js index 7955b14..ea55f4a 100644 --- a/src/server/SpaaaceServerEngine.js +++ b/src/server/SpaaaceServerEngine.js @@ -1,23 +1,26 @@ -'use strict'; - import ServerEngine from 'lance/ServerEngine'; const nameGenerator = require('./NameGenerator'); const NUM_BOTS = 3; export default class SpaaaceServerEngine extends ServerEngine { + constructor(io, gameEngine, inputOptions) { super(io, gameEngine, inputOptions); this.scoreData = {}; } + // when the game starts, create robot spaceships, and register + // on missile-hit events start() { super.start(); for (let x = 0; x < NUM_BOTS; x++) this.makeBot(); this.gameEngine.on('missileHit', e => { + // add kills if (this.scoreData[e.missile.ownerId]) this.scoreData[e.missile.ownerId].kills++; + // remove score data for killed ship delete this.scoreData[e.ship.id]; this.updateScore(); @@ -30,6 +33,7 @@ export default class SpaaaceServerEngine extends ServerEngine { }); } + // a player has connected onPlayerConnected(socket) { super.onPlayerConnected(socket); @@ -47,6 +51,7 @@ export default class SpaaaceServerEngine extends ServerEngine { socket.on('requestRestart', makePlayerShip); } + // a player has disconnected onPlayerDisconnected(socketId, playerId) { super.onPlayerDisconnected(socketId, playerId); @@ -62,6 +67,7 @@ export default class SpaaaceServerEngine extends ServerEngine { this.updateScore(); } + // create a robot spaceship makeBot() { let bot = this.gameEngine.makeShip(0); bot.attachAI();