From 3d2732077d06a134b6c1d2159799e868c36deb4d Mon Sep 17 00:00:00 2001 From: Oliver-Akins Date: Thu, 24 Dec 2020 21:51:49 -0700 Subject: [PATCH] Create Team object --- server/src/objects/Team.ts | 58 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 server/src/objects/Team.ts diff --git a/server/src/objects/Team.ts b/server/src/objects/Team.ts new file mode 100644 index 0000000..90d4d5c --- /dev/null +++ b/server/src/objects/Team.ts @@ -0,0 +1,58 @@ +import { Player } from "./Player"; + +export class Team { + public guessers: Player[]; + public writer: Player; + private _hand: string[]; + private _questions: string[]; + private _answers: string[]; + + constructor() { + this._answers = new Array(8).fill(``); + this._questions = []; + this._hand = []; + }; + + + /* + * The getters for the various class properties + */ + get hand(): string[] { return this._hand; }; + get answers(): string[] { return this._answers; }; + + + public addQuestions(questions: string[]): void { + /** + * Adds the question(s) to the medium's hand + * + * @param questions -> The array of question text to add the medium's + * hand. + */ + this._questions.push(...questions); + }; + + + public removeCard(question: string) { + /** + * Removes the given question from the medium's hand + * + * @param question -> The card text to remove from the hand. + */ + this._hand = this._hand.filter(x => x != question); + }; + + + public modifyAnswer(answerIndex: number, answer: string) { + /** + * Takes the value of an answer and modifies in the storage. + * + * @param answerIndex -> The value of the answer between 1 and 8 (inclusive) + * @param answer -> The new answer for that index + * @throws Error -> If the answerIndex is not in range + */ + if (answerIndex > this._answers.length || answerIndex <= 0) { + throw new Error(`Cannot set answer at index ${answerIndex}.`) + }; + this._answers[answerIndex - 1] = answer; + }; +}; \ No newline at end of file