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 @@ - + \ No newline at end of file diff --git a/src/views/server.hbs b/src/views/server.hbs index 6d74c55..9385a28 100644 --- a/src/views/server.hbs +++ b/src/views/server.hbs @@ -7,8 +7,67 @@ padding: 0; } + @font-face { + font-family: Mario; + src: url('/assets/SuperMario256.ttf'); + } + body { overflow-x: hidden; + font-family: Mario; + cursor: none; + } + + h1, + h2, + h3 { + color: #FFC107; + padding: 5%; + text-align: center; + opacity: 1; + transition: opacity .1s ease-in; + text-shadow: -3px -3px #FAFAFA, + 1px 1px #757575, + 2px 2px #757575, + 3px 3px #757575, + 4px 4px #757575, + 5px 5px #757575, + 6px 6px #757575; + } + + h1 { + font-size: 600%; + padding-bottom: 0; + } + + h2 { + padding-top: .5%; + padding-bottom: 0; + font-size: 400%; + } + + h3 { + font-size: 300%; + text-shadow: none; + padding-top: 0; + padding-bottom: 1%; + } + + ol { + padding: 0 5%; + list-style-type: decimal-leading-zero; + width: 90%; + padding-bottom: 2%; + } + + ol li { + font-size: 140%; + text-align: center; + } + + flexbox { + display: flex; + justify-content: space-around; } img.check { @@ -16,20 +75,15 @@ } img.checkmark { - content: ""; display: block; position: absolute; width: 200px; - top: 180px; - left: 680px; + margin-top: 180px; + margin-left: 130px; height: 200px; z-index: 1; } - img.checkmark.left { - left: 140px; - } - img.checkmark.hidden { display: none; } @@ -41,18 +95,31 @@ - - - - Mario - - - - - Luigi - +

Super + MARIO

+

QR-Code scannen um zu spielen

+ + + + + + + + + + + + + + +

Highscores

+ +
    +
      +
        +
        @@ -68,18 +135,17 @@