diff --git a/game/components/Receiver.ts b/game/components/Receiver.ts index 97e0026..de78121 100644 --- a/game/components/Receiver.ts +++ b/game/components/Receiver.ts @@ -63,13 +63,17 @@ export class Receiver { case "sendClue": console.log('Case sendClue reached'); let legalClue: boolean = RuleEnforcer.isLegalClue(message.clue); + let isWordOnBoard: boolean = RuleEnforcer.isWordOnBoard(message.clue, this.game.board.cards); let theirTurn: boolean = RuleEnforcer.isPlayerTurn(this.game, this.game.getPlayerById(message.id)); let validNum: boolean = RuleEnforcer.isValidNum(message.clue) - if(legalClue && theirTurn && validNum) { + if(legalClue && !isWordOnBoard && theirTurn && validNum) { this.game.initializeClue(message.clue); } else { - if(!legalClue) { - socket.send(JSON.stringify({ action: "invalidClueWord", })); + if(isWordOnBoard){ + socket.send(JSON.stringify({ action: "invalidClueWord", reason: "wordOnBoard"})); + } + else if(!legalClue) { + socket.send(JSON.stringify({ action: "invalidClueWord", reason: "notWord"})); } else if(!validNum) { socket.send(JSON.stringify({ action: "invalidClueNum", })); diff --git a/game/components/RuleEnforcer.ts b/game/components/RuleEnforcer.ts index 165f4f0..0fb9530 100644 --- a/game/components/RuleEnforcer.ts +++ b/game/components/RuleEnforcer.ts @@ -11,7 +11,7 @@ import { Team, Turn } from '../constants/Constants'; import { Game } from './Game' export module RuleEnforcer { - export function isValidName(name) { return name.length > 0; } + export function isValidName(name) { return name.length > 0 ; } export function isValidNum(clue) { return clue.num >= 0 && clue.num <= 9; @@ -21,6 +21,10 @@ export module RuleEnforcer { return words.check(clue.word.toLocaleLowerCase()); } + export function isWordOnBoard(clue: Clue, cards: Card[]): boolean { + return cards.filter(card => card.word.toLocaleLowerCase() === clue.word.toLocaleLowerCase()).length > 0; + } + export function isPlayerTurn(game: Game, player: SPlayer) { return game.currTeam === player.team && game.turn === player.role; }