UNPKG

pokie

Version:

A server-side video slot game logic framework for JavaScript and TypeScript.

51 lines 1.39 kB
import { GameSessionConfig, NoWinAmount, } from "pokie"; export class GameSession { constructor(config = new GameSessionConfig(), winAmountCalculator = new NoWinAmount()) { this.config = config; this.winCalculator = winAmountCalculator; this.bet = this.getInitialBet(); this.credits = config.getCreditsAmount(); } getCreditsAmount() { return this.credits; } setCreditsAmount(creditsAmount) { this.credits = creditsAmount; } getWinAmount() { return this.winCalculator.getWinAmount(); } getAvailableBets() { return this.config.getAvailableBets(); } getBet() { return this.bet; } setBet(bet) { if (!this.config.isBetAvailable(bet)) { this.bet = this.getAvailableBets()[0]; } else { this.bet = bet; } } canPlayNextGame() { return this.credits >= this.bet; } play() { if (this.canPlayNextGame()) { this.credits -= this.bet; } } getInitialBet() { let initialBet; if (this.config.isBetAvailable(this.config.getBet())) { initialBet = this.config.getBet(); } else { initialBet = this.config.getAvailableBets()[0]; } return initialBet; } } //# sourceMappingURL=GameSession.js.map