You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.4 KiB
89 lines
2.4 KiB
//Imports
|
|
const Card = require("./cards/Card");
|
|
const ChooseColor = require("./cards/special/ChooseColor");
|
|
const Skip = require("./cards/special/Skip");
|
|
const PlusAmount = require("./cards/special/PlusAmount");
|
|
const Reverse = require("./cards/special/Reverse");
|
|
const uno = require("./uno");
|
|
const Player = require("./Player");
|
|
|
|
//Um generatePool zu exportieren, muss es in eine Klasse konvertiert werden
|
|
class Game {
|
|
|
|
//Erstellt ein Spiel mit SpielerAnzahl und Array mit Regeln, initialisiert dann das Spiel
|
|
constructor(playerAmount, rules) {
|
|
|
|
this._cardOnDeck = null;
|
|
this._currentPlayer = 0;
|
|
this._direction = 0;
|
|
this._players = [];
|
|
|
|
this._playerAmount = playerAmount;
|
|
this._rules = rules;
|
|
|
|
this.initGame();
|
|
}
|
|
|
|
initGame(){
|
|
this._cardPool = this.generatePool();
|
|
this.createPlayers(this._playerAmount);
|
|
}
|
|
|
|
//Gibt ein Array zurück mit allen Karten, die in einem Uno Spiel sind
|
|
generatePool(){
|
|
|
|
//Array wird erstellt, welches später zurückgegeben wird und alle Karten beinhaltet
|
|
let pool = [];
|
|
|
|
//Pool aus Karten generieren
|
|
for (let k = 0; k < 2; k++) {
|
|
|
|
//Special Karten werden hinzugefügt
|
|
for (let j = 1; j < (uno.CARD_COLORS.length); j++) {
|
|
|
|
pool.push(new Reverse("R", uno.CARD_COLORS[j])); // 8x Reverse
|
|
pool.push(new PlusAmount("+2", uno.CARD_COLORS[j])); // 8x +2
|
|
pool.push(new Skip("S", uno.CARD_COLORS[j])); // 8x Skip
|
|
|
|
if (k === 0) {
|
|
|
|
pool.push(new ChooseColor("CC")); // 4x ChooseColor
|
|
pool.push(new PlusAmount("+4", uno.CARD_COLORS[0])); // 4x +4
|
|
|
|
}
|
|
|
|
//Normale Karten werden hinzugefügt
|
|
for (let i = 0; i <= 9; i++) {
|
|
|
|
if (k === 1 && i === 0) continue;
|
|
pool.push(new Card(i, uno.CARD_COLORS[j])); // 76x (2x 4x 1-9 + 4x 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Array mit Karten wird zurückgegeben
|
|
return pool;
|
|
}
|
|
|
|
createPlayers(playerAmount){
|
|
for (let i = 0; i < playerAmount; i++){
|
|
this._players.push(new Player("Player" + (i + 1), this));
|
|
}
|
|
}
|
|
|
|
//Gib den Pool mit allen UnoKarten zurück
|
|
get cardPool(){
|
|
return this._cardPool;
|
|
}
|
|
|
|
get players(){
|
|
return this._players;
|
|
}
|
|
|
|
}
|
|
|
|
//Exportiert Modul Game
|
|
module.exports = Game;
|