From 889c843aa7c40dba8b611477e924947c81438093 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Tue, 7 Feb 2023 10:46:18 +0100 Subject: [PATCH] deck create, remove the cards from the last one --- src/Console/main.js | 54 +++++++++++++++++++++----------- src/Model/Card4WithoutOutline.js | 10 +++--- src/Model/Deck.js | 15 ++++----- src/Model/Factory.js | 28 ++++++++--------- 4 files changed, 62 insertions(+), 45 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 2b9de4d..2668f88 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -31,28 +31,46 @@ console.groupEnd(); console.group('Deck'); -let deck = new Deck([0,1,3,4]); -console.log(`All cards with 4 attributes size ${deck.allCards.length}`); -console.log(`size output ${deck.outputCards.length}`); +let deck = new Deck([0,1,2,3]); +console.log(`All cards : ${deck.allCards.length}`); //Display all cards -console.log(`All cards`); -deck.allCards.forEach(e => { - //console.log(e.color,e.number,e.shape,e.filling); - console.log(e.color,e.number,e.filling,e.outline); - //console.log(e.color,e.number,e.shape,e.outline); -}); -console.log(`Output cards`); -// deck.outputCards.forEach(e => { -// console.log(e.getAttributes()); +console.log(`All cards display`); +// deck.allCards.forEach(e => { +// console.log(e.color,e.number,e.shape,e.filling);//no outline +// //console.log(e.color,e.number,e.filling,e.outline);//no shape +// //console.log(e.color,e.number,e.shape,e.outline);//no filling // }); +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`); +deck.outputCards.forEach(e => { + console.log(e.getAttributes()); +}); console.log(`set already made ${deck.setMade}`); -console.log(`remaining cards:`); -deck.setMade.forEach(e => { - console.log(e.color,e.number,e.shape,e.filling); - }); +// deck.setMade.forEach(e => { +// console.log(e.color,e.number,e.shape,e.filling); +// }); -let customCard=[new Card('red',1,'diamond','stripped')]; -//deck.checkSet(customCard); +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`); +deck.outputCards.forEach(e => { + console.log(e.getAttributes()); +}); //let deck5 = new Deck([0,1,2,3,4]); diff --git a/src/Model/Card4WithoutOutline.js b/src/Model/Card4WithoutOutline.js index c52c2f1..b1db83c 100644 --- a/src/Model/Card4WithoutOutline.js +++ b/src/Model/Card4WithoutOutline.js @@ -1,6 +1,9 @@ class Card4WithoutOutline extends Card{ constructor(color, number, shape, filling){ super(); + if(color==''){ + throw new EmptyParamaterException('Color'); + } if(number==''){ throw new EmptyParamaterException('Number'); } @@ -10,16 +13,13 @@ class Card4WithoutOutline extends Card{ if(filling==''){ throw new EmptyParamaterException('Filling'); } - if(color==''){ - throw new EmptyParamaterException('Color'); - } + this.color=color; this.number=number; this.shape=shape; this.filling=filling; - this.color=color; } getAttributes(){ - return [this.number,this.shape,this.filling,this.color]; + return [this.color,this.number,this.shape,this.filling]; } equals(card){ return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.color===card.color; diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 94df7a6..57e9d23 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -4,9 +4,10 @@ class Deck{ * @param {*} attributes : array with the attributes index for the cards */ constructor(attributes){ - console.log(attributes); + //console.log(attributes); this.allCards=this.createCards(attributes);// All the cards in the game - this.remainingCards=this.allCards;// cards in the stack + this.remainingCards=[] + 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(); @@ -41,7 +42,7 @@ class Deck{ checkSet(selectedCards){ if(true){//isSet(selectedCards)){ selectedCards.forEach(e => { - this.removeFromRemainingCards(e); + this.removeFromoutputCards(e); }); } } @@ -49,13 +50,13 @@ class Deck{ * * @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards */ - removeFromRemainingCards(selectedCards){//better check of card type more opti + removeFromoutputCards(selectedCards){//better check of card type more opti let set=[]; - for(let i=0; i{ - console.log("tab index") - console.log(e); - }); return attributesRequiredTmp; } concreteCardCreation(arrayOfAttributes, length){ @@ -51,7 +50,6 @@ class Factory{ tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o])); } else if(attributes[2][0]===0){ - console.log("jrentre la frro") tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o])); } else if(attributes[3][0]===0){