diff --git a/uno/index.html b/uno/index.html index d0977e9..3b1bf8b 100644 --- a/uno/index.html +++ b/uno/index.html @@ -5,7 +5,7 @@ Uno - - + + \ No newline at end of file diff --git a/uno/js/Game.js b/uno/node/js/Game.js similarity index 81% rename from uno/js/Game.js rename to uno/node/js/Game.js index bc6c028..bfc1ba4 100644 --- a/uno/js/Game.js +++ b/uno/node/js/Game.js @@ -1,10 +1,11 @@ //Imports -const uno = require("./uno"); 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 { @@ -12,6 +13,11 @@ 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; @@ -20,6 +26,7 @@ class Game { initGame(){ this._cardPool = this.generatePool(); + this.createPlayers(this._playerAmount); } //Gibt ein Array zurück mit allen Karten, die in einem Uno Spiel sind @@ -61,11 +68,21 @@ class Game { 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 diff --git a/uno/js/Player.js b/uno/node/js/Player.js similarity index 72% rename from uno/js/Player.js rename to uno/node/js/Player.js index 51c98b3..5b735ae 100644 --- a/uno/js/Player.js +++ b/uno/node/js/Player.js @@ -2,8 +2,9 @@ class Player { //Erstellt ein Spieler mit einem Namen - constructor(name) { + constructor(name, gameInstanz) { + this._game = gameInstanz; this._name = name; //Name des Spielers this._turn = false; //Ob Spieler gerade am Zug this._hand = []; @@ -11,6 +12,13 @@ class Player { } + drawCard(cards){ + for (let i = 0; i < cards; i++){ + this._hand.push(this._game.cardPool[0]); + this._game.cardPool.splice(0, 1); + } + } + //Gibt den Namen eines Spielers zurück get name() { return this._name; diff --git a/uno/js/cards/Card.js b/uno/node/js/cards/Card.js similarity index 100% rename from uno/js/cards/Card.js rename to uno/node/js/cards/Card.js diff --git a/uno/js/cards/special/ChooseColor.js b/uno/node/js/cards/special/ChooseColor.js similarity index 100% rename from uno/js/cards/special/ChooseColor.js rename to uno/node/js/cards/special/ChooseColor.js diff --git a/uno/js/cards/special/PlusAmount.js b/uno/node/js/cards/special/PlusAmount.js similarity index 100% rename from uno/js/cards/special/PlusAmount.js rename to uno/node/js/cards/special/PlusAmount.js diff --git a/uno/js/cards/special/Reverse.js b/uno/node/js/cards/special/Reverse.js similarity index 100% rename from uno/js/cards/special/Reverse.js rename to uno/node/js/cards/special/Reverse.js diff --git a/uno/js/cards/special/Skip.js b/uno/node/js/cards/special/Skip.js similarity index 100% rename from uno/js/cards/special/Skip.js rename to uno/node/js/cards/special/Skip.js diff --git a/uno/js/uno.js b/uno/node/js/uno.js similarity index 98% rename from uno/js/uno.js rename to uno/node/js/uno.js index 9a94c5f..7e55ce0 100644 --- a/uno/js/uno.js +++ b/uno/node/js/uno.js @@ -4,4 +4,4 @@ const CARD_COLORS = ["NONE", "BLUE", "GREEN", "RED", "YELLOW"]; //Exportiert CARD_COLORS module.exports = { CARD_COLORS: CARD_COLORS, -} \ No newline at end of file +} diff --git a/uno/tests/test_Card.test.js b/uno/node/tests/test_Card.test.js similarity index 100% rename from uno/tests/test_Card.test.js rename to uno/node/tests/test_Card.test.js diff --git a/uno/tests/test_Game.test.js b/uno/node/tests/test_Game.test.js similarity index 100% rename from uno/tests/test_Game.test.js rename to uno/node/tests/test_Game.test.js diff --git a/uno/tests/test_Player.test.js b/uno/node/tests/test_Player.test.js similarity index 62% rename from uno/tests/test_Player.test.js rename to uno/node/tests/test_Player.test.js index f817b56..33685a5 100644 --- a/uno/tests/test_Player.test.js +++ b/uno/node/tests/test_Player.test.js @@ -2,6 +2,7 @@ const Player = require('../js/Player'); const Card = require("../js/cards/Card"); const uno = require("../js/uno"); +const Game = require("../js/Game"); //Instanz CARD_COLORS aus uno.js const CARD_COLORS = uno.CARD_COLORS; @@ -14,7 +15,7 @@ describe('Spieler erstellen', () => { //Vor jedem Test, neuen Spieler erstellen beforeEach(() => { - player = new Player('SpielerName'); + player = new Player('SpielerName', null); }) //Testet ob der Name im Konstruktor richtig gesetzt wurde @@ -50,4 +51,29 @@ describe('Spieler erstellen', () => { }); +}); + +//Testet die Spieler Funktionalitäten +describe('Spieler Funktionalitäten', () => { + + //Erstellt ein Spiel + let game = new Game(2, null); + + //Testet, ob ein Spieler eine Karte aus dem CardPool vom Game ziehen kann + it('Karten ziehen', () => { + + //Nimmt die Anzahl der Karten im Deck und speichert sie + let cardAmount = game.cardPool.length; + + //Funktion vom Player ausführen zum Karte ziehen + game.players[0].drawCard(1); + + //Testet, ob die Kate aus cardPool entfernt wurde + expect(game.cardPool.length).toBe(cardAmount - 1); + + //Testet, ob der Spieler jetzt eine Karte auf der Hand hat + expect(game.players[0].hand.length).toBe(1); + + }); + }); \ No newline at end of file diff --git a/uno/tests/test_Uno.test.js b/uno/node/tests/test_Uno.test.js similarity index 100% rename from uno/tests/test_Uno.test.js rename to uno/node/tests/test_Uno.test.js