From bdc5ac82cd9236ff6f850286803daed4b80772f9 Mon Sep 17 00:00:00 2001 From: Nicolas Fritz Date: Fri, 27 Jan 2023 11:33:51 +0100 Subject: [PATCH] =?UTF-8?q?Rule=20stackCards=20hinzugef=C3=BCgt=20Mit=20+K?= =?UTF-8?q?arten=20andere=20+Karten=20Blocken=20oder=20sie=20stacken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uno/web/Game.js | 58 +++++++++++++++++++++++++---- uno/web/Player.js | 8 +++- uno/web/cards/special/PlusAmount.js | 13 ++++++- uno/web/uno.js | 3 +- 4 files changed, 71 insertions(+), 11 deletions(-) diff --git a/uno/web/Game.js b/uno/web/Game.js index d598424..3a0bc02 100644 --- a/uno/web/Game.js +++ b/uno/web/Game.js @@ -23,6 +23,8 @@ export default class Game { this._playerAmount = playerAmount; //Anzahl der Spieler this._rules = rules; //Array mit Regeln für das Spiel + this._stack = 0; //Für PlusAmountKarten + //Für HTML this._style = new Style(this); @@ -160,19 +162,41 @@ export default class Game { this.players[this.currentPlayer].turn = false; } - setTimeout(()=>{ + setTimeout(() => { - //nächster Spieler wird gesetzt - this.currentPlayer = this.nextPlayer(); + //nächster Spieler wird gesetzt + this.currentPlayer = this.nextPlayer(); - this.players[this.currentPlayer].turn = true; + this.players[this.currentPlayer].turn = true; - //Aktualisiere das Deck des aktuellen Spielers, welche Karten er legen kann - this.refreshCanPutCard(); + //Aktualisiere das Deck des aktuellen Spielers, welche Karten er legen kann + this.refreshCanPutCard(); - //HTML + //HTML this.style.refreshHtml(); + + //PlusAmount + let cardName = (this.cardOnDeck.name === "+4" || this.cardOnDeck.name === '+2') ? '+' : null; + if (cardName === '+') { + for (let i = 0; i < this.currentPlayerInstanz.hand.length; i++) { + if (this.currentPlayerInstanz.hand[i].name === this.cardOnDeck.name) { + return; + } + } + } + + + if (this.stack !== 0) { + setTimeout(() => { + + this.currentPlayerInstanz.drawCard(this.stack, false, true); + this.stack = 0; + + }, 600); + + } + }, delay) } @@ -184,6 +208,18 @@ export default class Game { //Gehe alle Karten vom Deck durch for (let i = 0; i < currentPlayerCards.length; i++) { + if (this.stack !== 0) { + if (this.cardOnDeck.name === '+4' || this.cardOnDeck.name === '+2') { + + for (let j = 0; j < currentPlayerCards.length; j++) { + if (currentPlayerCards[j].name.toString() === this.cardOnDeck.name.toString()) { + this.players[this.currentPlayer].hand[j].canPut = true; + this.players[this.currentPlayer].canPlay = true; + } else this.players[this.currentPlayer].hand[j].canPut = false; + } + break; + } + } //Wenn Farbe oder Zahl gleich oder eine Karte, die keine Farbe hat if (this.cardOnDeck.name.toString() === currentPlayerCards[i].name.toString() || this.cardOnDeck.color === currentPlayerCards[i].color || currentPlayerCards[i].color === CARD_COLORS[0] || this.cardOnDeck.color === CARD_COLORS[0]) { @@ -274,4 +310,12 @@ export default class Game { return this._style; } + get stack() { + return this._stack; + } + + set stack(stack) { + this._stack = stack; + } + } \ No newline at end of file diff --git a/uno/web/Player.js b/uno/web/Player.js index d08ce0c..8934e01 100644 --- a/uno/web/Player.js +++ b/uno/web/Player.js @@ -43,14 +43,18 @@ export default class Player { } - if (nextTurn) { + setTimeout(() => { + this.game.refreshCanPutCard(); + this.game.style.showPlayerDeck(this.game.currentPlayerInstanz, true, false, false); + if (nextTurn) { this.game.nextTurn(); + } }, 300 + 500 * amount); - } + } diff --git a/uno/web/cards/special/PlusAmount.js b/uno/web/cards/special/PlusAmount.js index 382305c..d432dea 100644 --- a/uno/web/cards/special/PlusAmount.js +++ b/uno/web/cards/special/PlusAmount.js @@ -21,7 +21,18 @@ export default class PlusAmount extends Card { //Todo: Karten Stapeln Regel //lässt den nächsten Spieler den PlusAmount der Karte ziehen - this.game.players[this.game.nextPlayer()].drawCard(this.plus, false, false); + + if (this.rules !== null) { + if ('stackCards' in this.game.rules) { + if (this.game.rules.stackCards === true) { + this.game.stack = this.game.stack + this.plus; + } else + this.game.stack = this.plus; + } else + this.game.stack = this.plus; + } else + this.game.stack = this.plus; + if(this.plus === 4){ diff --git a/uno/web/uno.js b/uno/web/uno.js index c592f92..c422af6 100644 --- a/uno/web/uno.js +++ b/uno/web/uno.js @@ -4,8 +4,9 @@ import Game from "./Game.js"; export const CARD_COLORS = ["NONE", "BLUE", "GREEN", "RED", "YELLOW"]; let rules = { - startCards: 3, + startCards: 8, firstPlaySpecial: true, + stackCards: false, } $(()=>{