JSFiddle - React, Tailwind, and code Playground
JavaScript
Player = function(wonRound, currentCards, newCards) {
this.wonRound = wonRound;
this.currentCards = currentCards;
this.newCards = newCards;
}
Deck = {
suits: ["Clubs", "Diamonds", "Hearts", "Spades"],
cards: ["Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"],
deck: [],
shuffledDeck: [],
players: 2,
stPoint: 0,
distrubuteCards: 0,
TempshuffledDeck: [],
BuildDeck: function() {
//Builds the deck
for (var suit = 0; suit < this.suits.length; suit++) {
for (var card = 0; card < this.cards.length; card++) {
this.deck.push([this.cards[card], this.suits[suit]]);
}
}
console.log("DECK len" + this.deck.length);
this.distributeCards = this.deck.length / this.players;
return this.deck;
},
UpdateDeck: function(player1deck) {
console.log(player1deck.len);
//Builds the deck
for (var i = 0; i < player1deck.length; i++) {
for (var j = this.deck.length; j > 0; j--) {
if (this.deck[j] == player1deck[i]) {
// this.deck.splice(j, 1);
}
}
}
console.log("DECK len" + this.deck.length);
this.distributeCards = this.deck.length / this.players;
return this.deck;
},
ShuffleDeck: function() {
var i = this.deck.length;
var j = 0;
while (i--) {
j = Math.floor(Math.random() * (i + 1));
this.shuffledDeck.push(this.deck[j]);
this.deck.splice(j, 1);
}
return this.shuffledDeck;
},
DistributeCards: function(playerDeck) {
//Distributes half the deck to each player
console.log("STPOINT::"+this.stPoint);
for (var k = 0; k < this.distributeCards; k++) {
playerDeck.push(this.shuffledDeck[k+this.stPoint]);
}
this.stPoint = this.stPoint + this.distributeCards;
return playerDeck;
}
}
Player1 = new Player(false, [], []);
Player2 = new Player(false, [],...