From 62d2f8458ddf59def2f046d05bcc47cda2d80bfe Mon Sep 17 00:00:00 2001 From: MayteApolix <83069108+MayteApolix@users.noreply.github.com> Date: Sun, 16 Jan 2022 17:21:08 +0100 Subject: Finished splash screen and stat tracking --- draughts/app.js | 23 +++++- draughts/public/images/players.png | Bin 1972840 -> 12369 bytes draughts/public/splash.html | 56 ++++++++----- draughts/public/stylesheets/game.css | 15 +--- draughts/public/stylesheets/splash.css | 144 ++++++++++++++++++++++++++++++--- draughts/public/stylesheets/style.css | 10 +++ draughts/routes/index.js | 2 +- draughts/statTracker.js | 5 +- draughts/views/splash.ejs | 65 +++++++++------ 9 files changed, 249 insertions(+), 71 deletions(-) create mode 100644 draughts/public/stylesheets/style.css diff --git a/draughts/app.js b/draughts/app.js index 5a4bab7..86a8c69 100644 --- a/draughts/app.js +++ b/draughts/app.js @@ -7,6 +7,8 @@ const Color = require("./public/javascripts/color") const Messages = require("./public/javascripts/messages") const Environment = require("./environment") const indexRouter = require("./routes/index") +const stats = require("./statTracker"); +const { stat } = require("fs") /* Get the server port, if the user doesn't provide one then print an error to STDERR and exit */ const port = process.argv[2] @@ -46,6 +48,8 @@ wss.on("connection", ws => { game.ongoing = true game.messageClient({ head: Messages.WELCOME, body: Color.RED }, ws) game.messageOpponent({ head: Messages.START }, ws) + stats.totalGames++ + stats.ongoingGames++ game.nextTurn() } @@ -57,6 +61,8 @@ wss.on("connection", ws => { ws.on("close", () => { if (game.ongoing) game.messageOpponent({ head: Messages.DISCONNECT }, ws) + stats.ongoingGames-- + stats.totalGames-- env.removeGame(game) }) @@ -66,6 +72,8 @@ wss.on("connection", ws => { case Messages.RESIGN: if (game.ongoing) game.messageOpponent(msg, ws) + stats.ongoingGames-- + stats.totalGames-- env.removeGame(game) break case Messages.MOVED: @@ -80,8 +88,21 @@ wss.on("connection", ws => { } }, ws) game.move(msg.body) - + if (!game.nextTurn()) + var totalMoves = game.history.length + /* Update minimum amount of moves in stat tracker */ + if (totalMoves < stats.minimumMoves){ + stats.minimumMoves = totalMoves + } + /* Update average amount of moves in stat tracker */ + if (stats.averageMoves != Infinity){ + stats.averageMoves = (stats.averageMoves * (stats.totalGames - 1) + totalMoves) / stats.totalGames + } else { + stats.averageMoves = totalMoves + } + /* Remove ongoing game */ + stats.ongoingGames-- env.removeGame(game) break } diff --git a/draughts/public/images/players.png b/draughts/public/images/players.png index ed67933..b175f56 100644 Binary files a/draughts/public/images/players.png and b/draughts/public/images/players.png differ diff --git a/draughts/public/splash.html b/draughts/public/splash.html index 05cbcad..6a84b54 100644 --- a/draughts/public/splash.html +++ b/draughts/public/splash.html @@ -8,31 +8,45 @@
The record for the minimum amount of moves is: 32
-The average player completes a game in 56 moves
-There are 3 games currently ongoing
- - - -Move diagonally
-Take pieces
-Crown Kings
-The record for the minimum amount of moves is: 32
+The average player completes a game in 56 moves
+There are 3 games currently ongoing
+