Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Check winning conditions after three failed votes #4

Open
TomTomRixRix opened this issue Mar 29, 2020 · 1 comment
Open

[bug] Check winning conditions after three failed votes #4

TomTomRixRix opened this issue Mar 29, 2020 · 1 comment

Comments

@TomTomRixRix
Copy link

When enacting the top card of the draw pile after three failed votes the winning conditions have to be checked. It might be the case that this law is the final one for either liberals or fascists. So a check like update.liberal == 5 || update.fascist == 6 needs to be added at the end of this code block.

// voting was a fail
} else if (update.voteresult == "fail") {
// reset trackerenact.message so flashmessage doesn't go off
update.trackerenact = { topcard: "", message: "" };
update.electiontracker = room.electiontracker + 1;
// enact top policy if election tracker is at 3
if (update.electiontracker == 3) {
let drawpile = room.drawpile;
// console.log("tracker at 3. drawpile:", drawpile);
if (drawpile.length == 0) {
drawpile = drawpile.concat(room.discardpile);
update.discardpile = [];
// console.log("tracker at 3. concat discard into drawpile", drawpile);
}
let topCard = drawpile.splice(0, 1);
update.drawpile = drawpile;
update.trackerenact = {
topcard: topCard,
message: `a ${topCard} policy has been enacted!`
};
}
}
}

@TomTomRixRix TomTomRixRix changed the title Check winning conditions after three failed votes [bug] Check winning conditions after three failed votes Mar 29, 2020
@TomTomRixRix
Copy link
Author

This is the code for checking the winning condition after discarding law card when a vote has passed. The winning condition should be similar, thus this code could simply be reused.

// end of game
if (update.liberal == 5 || update.fascist == 6) {
update.state = "gameover";
if (update.liberal == 5) {
update.winner = "liberals";
update.reason = "liberals have passed 5 policies!";
} else if (update.fascist == 6) {
update.winner = "fascists";
update.reason = "fascists have passed 6 policies!";
}
update.players = room.players;
for (let i = 0; i < room.players.length; i += 1) {
update.players[i].side = Players.findOne(room.players[i].playerId).role;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant