From 0a583c01cb644cde1e95584863b8f3c6bc59f385 Mon Sep 17 00:00:00 2001 From: Alec Maier Date: Sat, 18 Apr 2020 17:09:46 -0400 Subject: [PATCH] Confirm player death, fix join bug --- server.js | 2 +- static/game.js | 4 +++- static/join.js | 8 ++++++-- static/styles.css | 3 +-- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/server.js b/server.js index 295c61f..bd01f36 100644 --- a/server.js +++ b/server.js @@ -109,7 +109,7 @@ io.on('connection', function(socket) { }); socket.on('joinGame', function(playerInfo) { const game = activeGames[Object.keys(activeGames).find((key) => key === playerInfo.code)]; - if (game && game.players.length < game.size) { + if (game && game.players.length < game.size && !game.players.find((player) => player.id === playerInfo.id)) { game.players.push({name: playerInfo.name, id: playerInfo.id}); console.log(playerInfo.name + " joined the game!"); socket.emit('success'); diff --git a/static/game.js b/static/game.js index ceec169..9c5a2f0 100644 --- a/static/game.js +++ b/static/game.js @@ -340,7 +340,9 @@ function endGameDueToTimeExpired() { } function killPlayer() { - socket.emit("killPlayer", currentGame.players.find((player) => player.id === sessionStorage.getItem("id")).id, currentGame.accessCode); + if(confirm("Are you sure you are dead?")) { + socket.emit("killPlayer", currentGame.players.find((player) => player.id === sessionStorage.getItem("id")).id, currentGame.accessCode); + } } function renderLobby() { diff --git a/static/join.js b/static/join.js index 6783e12..512e2e0 100644 --- a/static/join.js +++ b/static/join.js @@ -3,12 +3,14 @@ import { utility } from './util.js' // respond to the game state received from the server socket.on('joinError', function(message) { - document.getElementById("code").classList.add("error"); - document.getElementById("join-error").innerText = message; + document.getElementById("join-btn").classList.remove('disabled'); + document.getElementById("code").classList.add("error"); + document.getElementById("join-error").innerText = message; }); // respond to the game state received from the server socket.on('success', function() { + document.getElementById("join-btn").classList.remove('disabled'); if (document.getElementById("code").classList.contains("error")) { document.getElementById("code").classList.remove("error"); document.getElementById("join-error").innerText = ""; @@ -21,6 +23,7 @@ socket.on('success', function() { }); document.getElementById("join-btn").addEventListener("click", function() { + document.getElementById("join-btn").classList.add('disabled'); if (document.getElementById("name").value.length > 0) { const code = document.getElementById("code").value.toString().trim().toLowerCase(); if (document.getElementById("name").classList.contains("error")) { @@ -33,6 +36,7 @@ document.getElementById("join-btn").addEventListener("click", function() { const playerInfo = {name: document.getElementById("name").value, id: playerId, code: code}; socket.emit('joinGame', playerInfo); } else { + document.getElementById("join-btn").classList.remove('disabled'); document.getElementById("name").classList.add("error"); document.getElementById("name-error").innerText = "Name is required."; } diff --git a/static/styles.css b/static/styles.css index e4522e2..c811aeb 100644 --- a/static/styles.css +++ b/static/styles.css @@ -918,9 +918,8 @@ label { opacity: 0.5; color: gray; background-color: white; - border: none; pointer-events: none; - + border: none; } .hidden {