diff --git a/.gitignore b/.gitignore
index 40b878d..f90a3f4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,2 @@
-node_modules/
\ No newline at end of file
+node_modules/
+scores.json
\ No newline at end of file
diff --git a/assets/SuperMario256.ttf b/assets/SuperMario256.ttf
new file mode 100644
index 0000000..5e1ccd4
Binary files /dev/null and b/assets/SuperMario256.ttf differ
diff --git a/server.js b/server.js
index 435eea1..b9f9441 100644
--- a/server.js
+++ b/server.js
@@ -6,7 +6,10 @@ const express = require('express'),
// wsEngine: 'ws'
}),
exphbs = require('express-handlebars'),
- qrCode = require('branded-qr-code');
+ qrCode = require('branded-qr-code'),
+ fs = require('fs');
+
+const scores = JSON.parse(fs.readFileSync('scores.json', 'utf8'));
/** CONSTANTS */
const HOST = 'http://100.119.37.224:8080/client/';
@@ -14,11 +17,13 @@ const HOST = 'http://100.119.37.224:8080/client/';
const players = [
{
type: 'mario',
+ name: 'Mario',
id: guid(),
score: 0
},
{
type: 'luigi',
+ name: 'Luigi',
id: guid(),
score: 0
},
@@ -95,6 +100,8 @@ clientNSP.on('connection', socket => {
setTimeout(() => monitorNSP.emit('updateGameState', 1), 2000);
let pl = getPlayerFromId(socket.request.headers.referer.split('/').slice(-1)[0]);
+ socket.on('changeName', name => pl.name = name);
+
socket.on('moveStart_left', () => {
console.log('moveStart_left: ' + pl.type);
monitorNSP.emit('moveStart_left', pl.type);
@@ -125,17 +132,37 @@ clientNSP.on('connection', socket => {
console.log('moveEnd_crouch: ' + pl.type);
});
-
socket.on('disconnect', () => {
console.log('Client disconnected.');
+ count--;
monitorNSP.emit('clientDisconnect', getPlayerFromId(id).type);
});
});
-
+let playerDeaths = 0;
monitorNSP.on('connection', socket => {
console.log('Monitor connected.');
+ socket.emit('handshake', {
+ scores,
+ marioId: players[0].id,
+ luigiId: players[1].id,
+ });
+ socket.on('playerDie', options => {
+ console.log(options.score)
+ playerDeaths++;
+ let pl = players.filter(el => el.type == options.player)[0];
+ pl.score = options.score;
+ if (pl.score > 0) {
+ scores.push({ name: pl.name, score: pl.score });
+ fs.writeFile('scores.json', JSON.stringify(scores));
+ }
+ if (playerDeaths === 2) {
+ setTimeout(() => {
+ monitorNSP.emit('handshake', { scores, marioId: players[0].id, luigiId: players[1].id, });
+ }, 4000);
+ }
+ });
socket.on('disconnect', () => {
console.log('Monitor disconnected.');
});
diff --git a/src/views/client.hbs b/src/views/client.hbs
index 3c93ae7..e895c05 100644
--- a/src/views/client.hbs
+++ b/src/views/client.hbs
@@ -48,7 +48,7 @@
background-color: #2196F3;
}
- button#crouch,
+ button#name,
button#jump {
right: 5%;
}
@@ -58,7 +58,7 @@
background-color: #4CAF50;
}
- button#crouch {
+ button#name {
bottom: calc(40% / 3);
background-color: #E53935;
}
@@ -100,7 +100,7 @@
-
+