|
@ -42,16 +42,20 @@ class Game { |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Startet das Spiel
|
|
|
start(){ |
|
|
start(){ |
|
|
if (this._cardPool === [] || this._players === []){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Wenn das Spiel noch nicht initialisiert wurde, initialisiere es
|
|
|
|
|
|
if (this._cardPool === [] || this._players === []) |
|
|
this.initGame(); |
|
|
this.initGame(); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
gameLoop(){ |
|
|
gameLoop(){ |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
@ -110,47 +114,66 @@ class Game { |
|
|
|
|
|
|
|
|
//Beendet den Zug des aktuellen Spielers und beginnt den Zug des nächsten Spielers
|
|
|
//Beendet den Zug des aktuellen Spielers und beginnt den Zug des nächsten Spielers
|
|
|
nextTurn(){ |
|
|
nextTurn(){ |
|
|
//Testet ob Spiel Gewonnen
|
|
|
|
|
|
|
|
|
//Testet, ob Spiel Gewonnen
|
|
|
for (let i = 0; i < this._players.length; i++){ |
|
|
for (let i = 0; i < this._players.length; i++){ |
|
|
if(this._players[i].hand.length <= 0){ |
|
|
if(this._players[i].hand.length <= 0){ |
|
|
|
|
|
|
|
|
|
|
|
//Breche den Loop ab
|
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Aktuellen Spieler kann, darf nicht mehr Spielen
|
|
|
this._currentPlayer.canPlay = false; |
|
|
this._currentPlayer.canPlay = false; |
|
|
|
|
|
|
|
|
//nächster Spieler
|
|
|
|
|
|
|
|
|
//nächster Spieler wird gesetzt
|
|
|
this._currentPlayer = this.nextPlayer(); |
|
|
this._currentPlayer = this.nextPlayer(); |
|
|
|
|
|
|
|
|
|
|
|
//Aktualisiere das Deck des aktuellen Spielers, welche Karten er legen kann
|
|
|
this.refreshCanPutCard(); |
|
|
this.refreshCanPutCard(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Testet alle Karten des aktuellen Spielers in seiner Hand, ob er sie legen kann
|
|
|
refreshCanPutCard(){ |
|
|
refreshCanPutCard(){ |
|
|
|
|
|
//Deck des aktuellen Spielers
|
|
|
let currentPlayerCards = this._players[this._currentPlayer].hand; |
|
|
let currentPlayerCards = this._players[this._currentPlayer].hand; |
|
|
|
|
|
|
|
|
|
|
|
//Gehe alle Karten vom Deck durch
|
|
|
for(let i = 0; i < currentPlayerCards.length; i++){ |
|
|
for(let i = 0; i < currentPlayerCards.length; i++){ |
|
|
|
|
|
|
|
|
|
|
|
//Wenn Farbe oder Zahl gleich oder eine Karte, die keine Farbe hat
|
|
|
if(this._cardOnDeck.name.toString() === currentPlayerCards[i].name.toString() || |
|
|
if(this._cardOnDeck.name.toString() === currentPlayerCards[i].name.toString() || |
|
|
this._cardPool._color === currentPlayerCards[i].color || |
|
|
this._cardPool._color === currentPlayerCards[i].color || |
|
|
currentPlayerCards[i].color === CARD_COLORS[0] || |
|
|
currentPlayerCards[i].color === CARD_COLORS[0] || |
|
|
this.cardOnDeck.color === CARD_COLORS[0]) { |
|
|
this.cardOnDeck.color === CARD_COLORS[0]) { |
|
|
|
|
|
|
|
|
|
|
|
//Aktualisiere den Wert der Karte, sodass sie gelegt werden kann
|
|
|
this._players[this._currentPlayer].hand[i].canPut = true; |
|
|
this._players[this._currentPlayer].hand[i].canPut = true; |
|
|
|
|
|
|
|
|
if(!this._players[this._currentPlayer].canPlay) |
|
|
|
|
|
this._players[this._currentPlayer].canPlay = true; |
|
|
|
|
|
|
|
|
//Der Spieler kann nun Karten legen
|
|
|
|
|
|
this._players[this._currentPlayer].canPlay = true; |
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
//Sonst setze den Wert der Karte so, dass sie nicht gelegt werden kann
|
|
|
this._players[this._currentPlayer].hand[i].canPut = false; |
|
|
this._players[this._currentPlayer].hand[i].canPut = false; |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Errechne, wer der nächste Spieler ist
|
|
|
nextPlayer(){ |
|
|
nextPlayer(){ |
|
|
|
|
|
|
|
|
|
|
|
//Anhand der Spielrichtung errechnen
|
|
|
if(this._direction === 1) |
|
|
if(this._direction === 1) |
|
|
return (this._currentPlayer === this._players.length - 1) ? 0 : this._currentPlayer + 1; //bei normaler Richtung
|
|
|
return (this._currentPlayer === this._players.length - 1) ? 0 : this._currentPlayer + 1; //bei normaler Richtung
|
|
|
else |
|
|
else |
|
|
return (this._currentPlayer === 0) ? this._players.length - 1 : this._currentPlayer - 1; //bei Invertierter Richtung
|
|
|
return (this._currentPlayer === 0) ? this._players.length - 1 : this._currentPlayer - 1; //bei Invertierter Richtung
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Gib den Pool mit allen UnoKarten zurück
|
|
|
//Gib den Pool mit allen UnoKarten zurück
|
|
@ -173,10 +196,12 @@ class Game { |
|
|
this._cardOnDeck = card; |
|
|
this._cardOnDeck = card; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Gibt den aktuellen Spieler zurück
|
|
|
get currentPlayer(){ |
|
|
get currentPlayer(){ |
|
|
return this._currentPlayer; |
|
|
return this._currentPlayer; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//Gibt die aktuelle Ricktung zurück 1 = normal 2 = Invertiert
|
|
|
get direction(){ |
|
|
get direction(){ |
|
|
return this._direction; |
|
|
return this._direction; |
|
|
} |
|
|
} |
|
|