Merge branch 'master' into game-page-enhancements

This commit is contained in:
Alec Maier
2020-04-11 18:55:24 -04:00
committed by GitHub
3 changed files with 39 additions and 20 deletions

View File

@@ -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,22 +174,28 @@ 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);
player.dead = true;
player.deadAt = new Date().toJSON();
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;
player.deadAt = new Date().toJSON();
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";
}
}
}
});

View File

@@ -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",

View File

@@ -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);