Browse Source

Rule stackCards hinzugefügt

Mit +Karten andere +Karten Blocken oder sie stacken
main
Nicolas Fritz 2 years ago
parent
commit
bdc5ac82cd
  1. 58
      uno/web/Game.js
  2. 8
      uno/web/Player.js
  3. 13
      uno/web/cards/special/PlusAmount.js
  4. 3
      uno/web/uno.js

58
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;
}
}

8
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);
}
}

13
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){

3
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,
}
$(()=>{

Loading…
Cancel
Save