pokie
Version:
A server-side video slot game logic framework for JavaScript and TypeScript.
55 lines • 1.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.GameSession = void 0;
const pokie_1 = require("pokie");
class GameSession {
constructor(config = new pokie_1.GameSessionConfig(), winAmountCalculator = new pokie_1.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;
}
}
exports.GameSession = GameSession;
//# sourceMappingURL=GameSession.js.map