diff --git a/src/Console/main.js b/src/Console/main.js index 2668f88..6832fb1 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -30,8 +30,10 @@ try { console.groupEnd(); +// CREATE DECK + console.group('Deck'); -let deck = new Deck([0,1,2,3]); +let deck = new Deck([0,1,2,3],3); console.log(`All cards : ${deck.allCards.length}`); //Display all cards console.log(`All cards display`); @@ -54,23 +56,27 @@ console.log(`set already made ${deck.setMade}`); // console.log(e.color,e.number,e.shape,e.filling); // }); + +// CHECK SET +console.log("CHECKING SET") + console.log("Card to remove: ") console.log(deck.outputCards[0].getAttributes(),deck.outputCards[1].getAttributes(),deck.outputCards[2].getAttributes()) let customCard=[deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]]; deck.checkSet(customCard); console.log(`remaining cards : ${deck.remainingCards.length}`) console.log(`All cards : ${deck.allCards.length}`) - console.log(`remaining cards : ${deck.remainingCards.length}`) // deck.remainingCards.forEach(e => { // console.log(e.getAttributes()); // }); - console.log(`size output ${deck.outputCards.length}`); -console.log(`Output cards`); +console.group('Output cards'); deck.outputCards.forEach(e => { console.log(e.getAttributes()); }); +console.log(`nbCards : ${deck.nbCards}`); +console.groupEnd(); //let deck5 = new Deck([0,1,2,3,4]); diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 57e9d23..3ec6507 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -2,21 +2,24 @@ class Deck{ /** * * @param {*} attributes : array with the attributes index for the cards + * @author Bastien Jacquelin */ - constructor(attributes){ + constructor(attributes,nbCards){ //console.log(attributes); this.allCards=this.createCards(attributes);// All the cards in the game this.remainingCards=[] + this.nbCards=nbCards; this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array with all the set already mades (array of set) - this.createDeck(); + this.createDeck(12); } /** - * @brief creation of the deck : call factory to create the good cards + * @brief creation of the deck : 12 cards lay in front of the player + * @author Bastien Jacquelin */ - createDeck(){ - for (let i=0; i<12; i++){ + createDeck(nbCards){ + for (let i=0; i { @@ -47,8 +57,9 @@ class Deck{ } } /** - * - * @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards + * @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 + * @author Bastien Jacquelin */ removeFromoutputCards(selectedCards){//better check of card type more opti let set=[]; @@ -65,6 +76,7 @@ class Deck{ } else{ this.setMade.push(set); + this.createDeck(this.nbCards) } } } \ No newline at end of file diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 4e2aa5b..181aa59 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -3,6 +3,12 @@ class Factory{ let length=arrayOfAttributes.length this.product=this.concreteCardCreation(arrayOfAttributes,length); } + /** + * @brief check if i in arrayOfAttributes + * @param {*} i value + * @param {*} arrayOfAttributes array + * @returns boolean + */ inArray(i,arrayOfAttributes){ let finded=false; for (let j=0;j