From 9ada0a4d6f0efe24428145faed8947753ae9abe3 Mon Sep 17 00:00:00 2001 From: Alec Maier Date: Sat, 11 Apr 2020 14:29:02 -0400 Subject: [PATCH] Treat dream wolves as minions until they convert --- server.js | 46 +++++++++++++++++++++++++++++++--------------- static/cards.js | 2 +- static/game.js | 12 ------------ static/setup.js | 9 ++++++--- 4 files changed, 38 insertions(+), 31 deletions(-) diff --git a/server.js b/server.js index 7b118a5..0064e63 100644 --- a/server.js +++ b/server.js @@ -58,6 +58,16 @@ server.listen(process.env.PORT || 5000, function() { console.log('Starting server on port 5000'); }); +// If there are multiple dream wolves, convert them all. +function activateDreamWolvesIfNeeded(game) { + game.players.forEach((player) => { + if (!player.dead && player.card.role === "Dream Wolf") { + player.card.isTypeOfWerewolf = true; + console.log("player " + player.name + " was converted to a wolf!"); + } + }) +} + function teamWon(game) { let wolvesAlive = 0; let villagersAlive = 0; @@ -164,21 +174,27 @@ io.on('connection', function(socket) { let game = activeGames[Object.keys(activeGames).find((key) => key === code)]; if (game) { let player = game.players.find((player) => player.id === id); - game.players.find((player) => player.id === id).dead = true; - game.killedPlayer = player.name; - game.lastKilled = player.id; - game.killedRole = player.card.role; - game.message = player.name + ", a " + player.card.role + ", was killed!"; - console.log(game.message); - const winCheck = teamWon(game); - if (winCheck === "wolf") { - console.log("wolves won the game!"); - game.winningTeam = "wolf"; - game.status = "ended"; - } if (winCheck === "village") { - console.log("village won the game!"); - game.winningTeam = "village"; - game.status = "ended"; + if (player) { + player.dead = true; + game.killedPlayer = player.name; + game.lastKilled = player.id; + game.killedRole = player.card.role; + game.message = player.name + ", a " + player.card.role + ", was killed!"; + console.log(game.message); + if (player.card.role === "Werewolf" && game.hasDreamWolf) { + activateDreamWolvesIfNeeded(game); + } + const winCheck = teamWon(game); + if (winCheck === "wolf") { + console.log("wolves won the game!"); + game.winningTeam = "wolf"; + game.status = "ended"; + } + if (winCheck === "village") { + console.log("village won the game!"); + game.winningTeam = "village"; + game.status = "ended"; + } } } }); diff --git a/static/cards.js b/static/cards.js index 8a3fa4d..0d9b599 100644 --- a/static/cards.js +++ b/static/cards.js @@ -15,7 +15,7 @@ export const cards = [ role: "Dream Wolf", team: "evil", description: "If a Werewolf dies, you become a Werewolf. You do not wake up with the Werewolves until this happens.", - isTypeOfWerewolf: true + isTypeOfWerewolf: false }, { role: "Minion", diff --git a/static/game.js b/static/game.js index 62d6ab1..970d7e3 100644 --- a/static/game.js +++ b/static/game.js @@ -18,18 +18,6 @@ socket.on('state', function(game) { } }); -window.onblur = function() { // pause animations if the window is not in focus - this.document.querySelector("#overlay").style.animationPlayState = 'paused'; - this.document.querySelector("#killed-role").style.animationPlayState = 'paused'; - this.document.querySelector("#killed-name").style.animationPlayState = 'paused'; -}; - -window.onfocus = function() { // play animations when window is focused - this.document.querySelector("#overlay").style.animationPlayState = 'running'; - this.document.querySelector("#killed-role").style.animationPlayState = 'running'; - this.document.querySelector("#killed-name").style.animationPlayState = 'running'; -}; - function buildGameBasedOnState(game) { switch(game.status) { case "lobby": diff --git a/static/setup.js b/static/setup.js index d7c2ba6..54f4ac6 100644 --- a/static/setup.js +++ b/static/setup.js @@ -17,13 +17,14 @@ class Card { } class Game { - constructor(accessCode, size, deck, time) { + constructor(accessCode, size, deck, time, hasDreamWolf) { this.accessCode = accessCode; this.size = size; this.deck = deck; this.time = time; this.players = []; this.status = "lobby"; + this.hasDreamWolf = hasDreamWolf; this.endTime = null; } } @@ -230,11 +231,13 @@ function createGame() { // send a new game to the server, and then join it const playerInfo = {name: document.getElementById("name").value, code: code, id: id}; + let gameDeck = buildDeckFromQuantities(); const game = new Game( code, gameSize, - buildDeckFromQuantities(), - Math.ceil(document.getElementById("time").value) + gameDeck, + Math.ceil(document.getElementById("time").value), + gameDeck.find((card) => card.role === "Dream Wolf") !== undefined ); socket.emit('newGame', game, function() { socket.emit('joinGame', playerInfo);