diff --git a/src/models/pokerTable/index.ts b/src/models/pokerTable/index.ts index 5040aa7..6215361 100644 --- a/src/models/pokerTable/index.ts +++ b/src/models/pokerTable/index.ts @@ -1,7 +1,7 @@ //@collapse // Import Enums -import { PokerSeatEvents , LogLevel } from "../../enums"; +import { PokerSeatEvents, LogLevel } from "../../enums"; // Import Interfaces import { @@ -21,7 +21,7 @@ import { PokerPlayer } from "../pokerPlayer"; import { PokerSeat } from "../pokerSeat"; // Import Utils -import { generateUniqueId , logger} from "../../utils"; +import { generateUniqueId, logger } from "../../utils"; import { PokerGame } from "../pokerGame"; /** @@ -196,7 +196,7 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { */ private __gameInProgress: boolean = false; - private __game:PokerGameInterface|undefined = undefined; + private __game: PokerGameInterface | undefined = undefined; /************************************************************************************************************** * CONSTRUCTOR & INITIALIZERS @@ -293,9 +293,9 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { this.__seats?.push(seat); // seat.on(PokerSeatEvents.OCCUPIED,(event)=>{}) - seat.listenToEvent(PokerSeatEvents.OCCUPIED,{ - handler:(event:BaseEventInterface) => { - this.__startGame() + seat.listenToEvent(PokerSeatEvents.OCCUPIED, { + handler: (event: BaseEventInterface) => { + this.__startGame(); }, middlewares: [ (event, next) => { @@ -305,9 +305,8 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { this.__checkOccupancyCount(event, next); }, ], - }) + }); } - } } @@ -464,16 +463,16 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return this.__seats; } - /** + /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. * This method initiates the game flow, including assigning blinds and starting the rounds. * @returns {number} */ - public getGame(): PokerGameInterface|undefined { + public getGame(): PokerGameInterface | undefined { return this.__game; } - + /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. @@ -678,19 +677,18 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return true; } - /** * `getSeats` * Starts a new PokerGame if there are at least two active players at the PokerTable. * This method initiates the game flow, including assigning blinds and starting the rounds. * @returns {number} */ - private __setGameInProgress(bool:boolean): boolean { - this.__gameInProgress = bool ; + private __setGameInProgress(bool: boolean): boolean { + this.__gameInProgress = bool; return this.__gameInProgress; } - /** + /** * `setSeats` * @public * Returns the poker table's `id`. @@ -700,9 +698,11 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { * const rank = card.getRank(); * console.log(rank); // "A" */ - private __setGame(game: PokerGameInterface|undefined): PokerGameInterface|undefined { - this.__game = game; - return this.__game; + private __setGame( + game: PokerGameInterface | undefined + ): PokerGameInterface | undefined { + this.__game = game; + return this.__game; } private __occupySeat( @@ -723,17 +723,17 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { return false; } - /** + /** * #### Description * Checks seat availability to determine if it can be occupied by a player. * * @param {BaseEventInterface} event - The event object containing event data. * @param {() => void} next - The next middleware function to call if seat is available. */ - private __checkIsGameInProgress( + private __checkIsGameInProgress( event: BaseEventInterface, next: () => void - ): void|false { + ): void | false { if (this.isGameInProgress()) { logger.log( LogLevel.WARN, @@ -744,7 +744,7 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { ); return false; } - + event.lastModifiedAt = new Date(); next(); } @@ -754,32 +754,32 @@ class PokerTable extends BaseEventEmitter implements PokerTableInterface { next: () => void ): void | false { let occupiedSeats = 0; - + for (let i = 0; i < this.getSeats().length; i++) { let seat = this.getSeats()[i]; if (seat.getPlayer()) { occupiedSeats += 1; } } - + // Check if all seats are occupied if (occupiedSeats === this.getSeats().length) { - logger.log( - LogLevel.WARN, - "All seats are occupied", - event - ) + logger.log(LogLevel.WARN, "All seats are occupied", event); return false; } - + // Update the event timestamp and call the next middleware function event.lastModifiedAt = new Date(); next(); } private __startGame() { - let config:PokerGameConfig= {smallBlind:this.getSmallBlind(),bigBlind:this.getBigBlind(),players:[]} - let newGame = new PokerGame(config) + let config: PokerGameConfig = { + smallBlind: this.getSmallBlind(), + bigBlind: this.getBigBlind(), + players: [], + }; + let newGame = new PokerGame(config); this.__setGame(newGame); } }