Skip to content

Commit

Permalink
Merge pull request #31 from spj2401Dev/minus-point-on-picture-remove
Browse files Browse the repository at this point in the history
  • Loading branch information
spj2401Dev authored Jul 19, 2024
2 parents 3a86b81 + cf7ef73 commit 85e89e3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 3 deletions.
5 changes: 5 additions & 0 deletions client/pages/setWords/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ <h1 class="header-text">Set Prompts</h1>
<input type="number" placeholder="3" max="1000" min="1" step="1" id="votes" class="number-input">
</div>

<div class="block">
<input type="checkbox" id="penalty">
<label for="isTeam">One Point penalty for invalid Photo</label>
</div>

<div class="block">
<button class="button" id="word-suggestion">✨ Suggest Words</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions client/pages/setWords/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function submitPrompts() {
const promptInputs = promptContainer.getElementsByTagName("input");
const time = document.getElementById("duration").value;
const votes = document.getElementById("votes").value;
const penalty = document.getElementById("penalty").checked;
const prompts = [];

if (time < 1) {
Expand Down Expand Up @@ -108,6 +109,7 @@ function submitPrompts() {
wordsPerPlayer: wordsPerPlayer,
time: time,
votesPerPlayer: votes,
penalty: penalty,
};

fetch("/words", {
Expand Down
6 changes: 6 additions & 0 deletions src/controller/photoController.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import {
AddImageToPlayer,
GetFullPlayers,
DeclinePhoto,
AddVoteToWord
} from "../services/playerService.mjs";
import path from "path";
import webSocketService from "../services/webSocketService.mjs";
import fs from 'fs';
import { game } from "../models/game.mjs";

const uploadDir = "data/photos/";

Expand Down Expand Up @@ -109,6 +111,10 @@ export const DeclinePhotoController = async (req, res) => {
const word = req.body.word;
DeclinePhoto(playername, word);

if (game.removePoints) {
AddVoteToWord(word, playername, -1);
}

webSocketService.broadcast("Decline");

res.status(200).send("Photo declined.");
Expand Down
2 changes: 2 additions & 0 deletions src/controller/wordController.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const setWords = async (req, res) => {
wordsPerPlayer = req.body.wordsPerPlayer;
var time = req.body.time; // Time in Minutes
var votes = req.body.votesPerPlayer;
var penalty = req.body.penalty;

if (words.length + wordlist.length < wordsPerPlayer) {
return res.status(400).json({
Expand All @@ -28,6 +29,7 @@ export const setWords = async (req, res) => {
userWordList = words;
game.time = time;
game.votesPerPlayer = votes;
game.removePoints = penalty;

await changeGameStatus(GameStatus.STARTING)
webSocketService.broadcast('Words');
Expand Down
1 change: 1 addition & 0 deletions src/models/game.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const game = {
endTime: new Date(),
words: [],
votesPerPlayer: 0,
removePoints: false, // If true, one point is removed from the player if one of their pictures gets deleted by an Admin
};
6 changes: 3 additions & 3 deletions src/services/playerService.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function GetWinner() {
players.forEach((p) => {
if (!rankList.some((player) => player.player === p.name)) {
let completedPhotos = p.words.filter((w) => w.completed === true);
let votesScore = completedPhotos.reduce((acc, word) => acc + word.votes, 0);
let votesScore = p.words.reduce((acc, word) => acc + word.votes, 0);
let totalScore = completedPhotos.length + votesScore;

rankList.push({
Expand Down Expand Up @@ -157,7 +157,7 @@ export function VoteForPlayer(playername) {
}
}

export function AddVoteToWord(word, playername) {
export function AddVoteToWord(word, playername, amount = 1) {
let player = players.find((p) => p.name === playername);
if (!player) {
return;
Expand All @@ -166,7 +166,7 @@ export function AddVoteToWord(word, playername) {
if (!targetWord) {
return;
}
targetWord.votes += 1;
targetWord.votes += amount;
}

export function getVoteAmount(playername) {
Expand Down

0 comments on commit 85e89e3

Please sign in to comment.