From 87dc34b679a4e175a1ed995aa35456463ad56716 Mon Sep 17 00:00:00 2001 From: AtilioA Date: Thu, 26 Oct 2023 12:53:15 -0300 Subject: [PATCH] docs: add tsdoc to `Caravan` --- src/models/Caravan.ts | 7 ++++++ src/models/interfaces/ICaravan.ts | 40 ++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/models/Caravan.ts b/src/models/Caravan.ts index af4c290..15985e9 100644 --- a/src/models/Caravan.ts +++ b/src/models/Caravan.ts @@ -11,6 +11,13 @@ export class Caravan implements ICaravan { suit: CardSuit | null = null; bid: number = 0; + /** + * Creates a new caravan instance. + * @param cards - Initial cards for the caravan. + * @param direction - Initial direction for the caravan. + * @param suit - Initial suit for the caravan. + * @param bid - Initial bid for the caravan. + */ constructor(cards: ICard[] = [], direction: Direction | null = null, suit: CardSuit | null = null, bid: number = 0) { this.cards = cards; this.direction = direction; diff --git a/src/models/interfaces/ICaravan.ts b/src/models/interfaces/ICaravan.ts index 0f554d2..3ff8559 100644 --- a/src/models/interfaces/ICaravan.ts +++ b/src/models/interfaces/ICaravan.ts @@ -2,21 +2,59 @@ import { CardSuit } from "../../constants/cardConstants"; import { Direction } from "../../enums/directions"; import { ICard } from "./ICard"; +/** + * Defines the structure and functionality of a Caravan. + */ export interface ICaravan { + /** A list of cards that are in the caravan. */ cards: ICard[]; + /** The current direction of the caravan. */ direction: Direction | null; + /** The current suit of the caravan. */ suit: CardSuit | null; + /** The current bid of the caravan. */ bid: number; + /** + * Checks if the caravan is empty. + * @returns true if the caravan is empty, otherwise false. + */ isEmpty(): boolean; + + /** + * Retrieves the last valued card in the caravan. + * @returns the last valued card. + */ getLastValuedCard(): ICard; + /** + * Adds a card to the caravan. + * @param card - The card to be added. + */ addCard(card: ICard): void; + + /** + * Determines if a card can be added to the caravan. + * @param card - The card to be checked. + * @returns true if the card can be added, otherwise false. + */ canAddCard(card: ICard): boolean; - // Might not be needed (we'd just change the bid when cards are played) + /** + * Computes the total value of the caravan. + * @returns the total value. + */ computeValue(): number; + + /** + * Checks if the caravan is sold. + * @returns true if the bid is between 21 and 26, otherwise false. + */ isSold(): boolean; + /** + * Disbands the caravan and returns its cards. + * @returns a list of cards from the disbanded caravan. + */ disband(): ICard[]; }