import Player from "./class-player.js"; /** * Game class. */ class Game { #name = "My Game"; #language = "en-US"; #playerId = 0; #players = []; #roundWinners = []; #roundLosers = []; #gameWinners = []; #gameLosers = []; #state = "paused"; #turn; #currentTurn = 1; #maxTurn = 0; #currentRound = 1; #maxRound = 0; /** * Initialize a new Game instance. * @param {String} name - The game name. * @param {Object[]} players - The players. * @param {String} players[].username - The player username. * @param {Boolean} players[].ia - True to set the player as an IA. */ constructor(name, players) { this.#name = name; players.forEach((player) => { this.#players.push( new Player(++this.#playerId, player.username, player.ia) ); }); } set name(string) { this.#name = string; } get name() { return this.#name; } set language(languageCode) { this.#language = languageCode; } get language() { return this.#language; } set players(array) { array.forEach((player) => this.#players.push( new Player(++this.#playerId, player.username, player.ia) ) ); } get players() { return this.#players; } set roundWinners(array) { if (array.length > 0) { array.forEach((player) => this.#roundWinners.push(player)); } else { this.#roundWinners = []; } } get roundWinners() { return this.#roundWinners; } set roundLosers(array) { if (array.length > 0) { array.forEach((player) => this.#roundLosers.push(player)); } else { this.#roundLosers = []; } } get roundLosers() { return this.#roundLosers; } set gameWinners(array) { if (array.length > 0) { array.forEach((player) => this.#gameWinners.push(player)); } else { this.#gameWinners = []; } } get gameWinners() { return this.#gameWinners; } set gameLosers(array) { if (array.length > 0) { array.forEach((player) => this.#gameLosers.push(player)); } else { this.#gameLosers = []; } } get gameLosers() { return this.#gameLosers; } set state(string) { this.#state = string; } get state() { return this.#state; } set turn(generator) { this.#turn = generator; } get turn() { return this.#turn; } set currentTurn(int) { this.#currentTurn = int; } get currentTurn() { return this.#currentTurn; } set maxTurn(int = this.getPlayersNumber()) { this.#maxTurn = int; } get maxTurn() { return this.#maxTurn; } set currentRound(int) { this.#currentRound = int; } get currentRound() { return this.#currentRound; } set maxRound(int) { this.#maxRound = int; } get maxRound() { return this.#maxRound; } newPlayer(username) { this.players.push(new Player(++this.#playerId, username)); } getPlayersNumber() { return this.players.length; } getPlayer(number) { return this.players[number - 1]; } getCurrentPlayer() { return this.getPlayer(this.currentTurn); } getNextPlayer() { if (this.currentTurn < this.maxTurn) { return this.getPlayer(this.currentTurn + 1); } else { return this.getPlayer(1); } } isFirstTurn() { return this.currentTurn === 1; } isNewRound() { return this.currentRound > 1 && this.isFirstTurn(); } isGameOver() { return this.state === "ended"; } resetScore() { this.players.forEach((player) => { player.score = 0; }); } newGame() { this.roundWinners = []; this.roundLosers = []; this.gameWinners = []; this.gameLosers = []; this.state = "paused"; this.turn = this.#generateTurns(); this.currentTurn = 1; this.currentRound = 1; this.maxTurn = this.getPlayersNumber(); this.resetScore(); } setPlayerChoice(choice) { if (this.state === "running") { this.getCurrentPlayer().choice = choice; } } *#generateTurns() { this.currentRound = 1; while (this.maxRound ? this.currentRound <= this.maxRound : true) { this.currentTurn = 1; while (this.currentTurn <= this.maxTurn) { yield this.currentTurn; this.currentTurn++; } this.currentRound++; } this.stop(); this.setGameWinners(); this.setGameLosers(); return; } /** * Get a random choice from an array of choices. * @param {Array} array - The choices. * @returns {*} A random choice. */ getRandomChoice(array) { const randomIndex = Math.floor(Math.random() * array.length); return array[randomIndex]; } getOrderedScores() { let scores = []; this.players.forEach((player) => { scores.push(player.score); }); scores.sort((a, b) => a - b); return scores; } setGameWinners() { const scores = this.getOrderedScores(); const highestScore = scores.pop(); const winners = this.players.filter( (player) => player.score === highestScore ); this.gameWinners = winners; } setGameLosers() { const scores = this.getOrderedScores(); const lowestScore = scores.shift(); const losers = this.players.filter( (player) => player.score === lowestScore ); this.gameLosers = losers; } resume() { this.state = "running"; } pause() { this.state = "paused"; } stop() { this.state = "ended"; } launch() { this.newGame(); this.resume(); this.turn.next(); } } export default Game; t */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
import Button from './Button/Button';
import ButtonLink from './ButtonLink/ButtonLink';
import ButtonToolbar from './ButtonToolbar/ButtonToolbar';
import ButtonSubmit from './ButtonSubmit/ButtonSubmit';
export { Button, ButtonLink, ButtonToolbar, ButtonSubmit };