|
|
|
@ -14,24 +14,28 @@ class Deck{
|
|
|
|
|
this.setMade=[];// array of array with all the set already mades (array of set)
|
|
|
|
|
this.createDeck(12);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief creation of the deck : 12 cards lay in front of the player
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
createDeck(nbCards){
|
|
|
|
|
for (let i=0; i<nbCards; i++){
|
|
|
|
|
if(this.remainingCards.length==0){
|
|
|
|
|
console.log("PLUS DE CARTES");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
const rand = this.getRandCard();
|
|
|
|
|
this.outputCards.push(this.remainingCards[rand]);
|
|
|
|
|
this.remainingCards.splice(rand,1);
|
|
|
|
|
if(this.remainingCards.length==0){
|
|
|
|
|
console.log("PLUS DE CARTES");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if(){
|
|
|
|
|
this.createDeck(this.nbCards)
|
|
|
|
|
else{
|
|
|
|
|
for (let i=0; i<nbCards; i++){
|
|
|
|
|
const rand = this.getRandCard();
|
|
|
|
|
this.outputCards.push(this.remainingCards[rand]);
|
|
|
|
|
this.remainingCards.splice(rand,1);
|
|
|
|
|
}
|
|
|
|
|
if(setsCounter(this.outputCards,this.nbCards)==0){
|
|
|
|
|
this.createDeck(this.nbCards)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns random number in range of the array size
|
|
|
|
@ -41,6 +45,7 @@ class Deck{
|
|
|
|
|
const random = Math.floor(Math.random() * this.remainingCards.length);
|
|
|
|
|
return random;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param attributes : index of the attributes used
|
|
|
|
@ -51,6 +56,7 @@ class Deck{
|
|
|
|
|
let factory = new Factory(attributes)
|
|
|
|
|
return factory.product
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief verification of the validity of the set selected
|
|
|
|
|
* @param {*} selectedCards array of cards : set
|
|
|
|
@ -71,6 +77,7 @@ class Deck{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @brief when a set is made, need to remove the card from the array remainingCards
|
|
|
|
|
* @param {*} selectedCards cards which need to be removed from the outputcards
|
|
|
|
|