check if no set in deck and auto add 3 others. Finish, just need to uncomment line 66 in Deck.js to activate set verification
continuous-integration/drone/push Build is passing Details

pull/47/head
Bastien JACQUELIN 2 years ago
parent d37f88e8ee
commit 82e97e1096

@ -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

@ -112,10 +112,15 @@ function numberOfSets5(deck){
return res
}
function setsCounter(set, numberForSet){
/**
*
* @param {*} deck
* @param {*} numberForSet
* @returns
*/
function setsCounter(deck, numberForSet){
if(numberForSet === 3){
return numberOfSets3(set)
return numberOfSets3(deck)
}
if(numberForSet === 4){
return numberOfSets4(deck)

Loading…
Cancel
Save