From 4951e2b8e10eae548fbbeb2ac175b4490b90348d Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Mar 2023 11:09:26 +0100 Subject: [PATCH] card class only, can take multiple attributes, deck and card creation to do --- src/Console/main.js | 40 +++++++++++------------------ src/Model/Card.js | 33 +++++++++++++++--------- src/Model/Card4WithoutColor.js | 27 -------------------- src/Model/Card4WithoutFilling.js | 27 -------------------- src/Model/Card4WithoutNumber.js | 27 -------------------- src/Model/Card4WithoutOutline.js | 27 -------------------- src/Model/Card4WithoutShape.js | 27 -------------------- src/Model/Card5.js | 43 -------------------------------- 8 files changed, 36 insertions(+), 215 deletions(-) delete mode 100644 src/Model/Card4WithoutColor.js delete mode 100644 src/Model/Card4WithoutFilling.js delete mode 100644 src/Model/Card4WithoutNumber.js delete mode 100644 src/Model/Card4WithoutOutline.js delete mode 100644 src/Model/Card4WithoutShape.js delete mode 100644 src/Model/Card5.js diff --git a/src/Console/main.js b/src/Console/main.js index d3c5845..8e34e15 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -3,36 +3,26 @@ //import {Card} from '../Model/Card'; console.log("~#Test#~"); -let card4 = new Card4WithoutOutline('red','2','losange','full'); -console.group('Carte 4 attributes'); -console.log(`carte de 4 elements : ${card4.color}`); -console.groupEnd(); -let card5 = new Card5('blue','2','losange','full','pointillet'); -console.group('Carte 5 attributes'); -console.log(`carte de 5 elements : ${card5.color}`); -console.log(`carte de 5 elements : ${card5.outline}`); -console.log(`carte de 5 éléments instance de 5: ${card5 instanceof Card5}`); -console.log(`carte de 5 éléments accès par méthode idx 0: ${card5.getAttributes()[0]}`); -console.log(`carte de 5 éléments accès par méthode idx 4: ${card5.getAttributes()[4]}`); -console.groupEnd(); -console.group('Error'); -try { - let errCard = new Card5('blue','','losange','full','pointillet'); -}catch(errCard){ - if(errCard instanceof EmptyParamaterException){ - console.log('Error in constructor'); - } - else{ - console.error(errCard); - } -} +console.group('Card');//DONE +console.log('Passed') +/* +let card1=new Card({'color':'red','filling':'full'}); +let card2=new Card({'color':'red','filling':'full'}); +let card3=new Card({'color':'red','outline':'full'}); +let card4=new Card({'color':'red','filling':'empty'}); +console.log(card1.attributes);// ATTRIBUTES +console.log(card1.getAttributes());// ATTRIBUTES +console.log(card1.equals(card2));// TRUE +console.log(card1.equals(card3));//FALSE +console.log(card1.equals(card4));//FALSE +*/ console.groupEnd(); // CREATE DECK - console.group('Deck'); +/* console.log("~~BEGINNING~~"); let deck = new Deck([0,1,2,3],3); console.log(`All cards : ${deck.allCards.length}`); @@ -80,8 +70,8 @@ deck.setMade.forEach(e => {//tab of tab of cards of set made }) }); // console.log(deck.setMade) +*/ console.groupEnd(); - //let deck5 = new Deck([0,1,2,3,4]); //console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); // deck5.allCards.forEach(e => { diff --git a/src/Model/Card.js b/src/Model/Card.js index 2c0ab73..9420f3f 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,25 +1,34 @@ class Card{ + /** + * + * @param {*} attributes : dictionnary of attributes : key : name of the attributes and value : value of the attributes + */ constructor(attributes){ this.attributes=attributes; } - createAttributes(arrayOfAttributes){ - - } - - - - - /** * * @returns all attributes of a card */ - getAttributes(){} + getAttributes(){ + let att=[]; + Object.entries(this.attributes).forEach(function([key, value]) { + att.push(value); + }); + return att; + } /** * * @param {*} card card to be compared with the current obj * @returns boolean */ - equals(card){} - -}//export {Card} \ No newline at end of file + equals(card){ + let bool=true; + Object.entries(this.attributes).forEach(function([key, value]) { + if(card.attributes[key]!=value){ + bool=false; + } + }); + return bool; + } +} \ No newline at end of file diff --git a/src/Model/Card4WithoutColor.js b/src/Model/Card4WithoutColor.js deleted file mode 100644 index cbad689..0000000 --- a/src/Model/Card4WithoutColor.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutColor extends Card{ - constructor(number, shape, filling, outline){ - super(); - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.number=number; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutFilling.js b/src/Model/Card4WithoutFilling.js deleted file mode 100644 index b895c07..0000000 --- a/src/Model/Card4WithoutFilling.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutFilling extends Card{ - constructor(color,number, shape, outline){ - super(); - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.number=number; - this.shape=shape; - this.color=color; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.shape,this.color,this.outline]; - } - equals(card){ - return this.number===card.number && this.shape===card.shape && this.color===card.color && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutNumber.js b/src/Model/Card4WithoutNumber.js deleted file mode 100644 index 95abc61..0000000 --- a/src/Model/Card4WithoutNumber.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutNumber extends Card{ - constructor(color, shape, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.color,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.color===card.color && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutOutline.js b/src/Model/Card4WithoutOutline.js deleted file mode 100644 index b1db83c..0000000 --- a/src/Model/Card4WithoutOutline.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutOutline extends Card{ - constructor(color, number, shape, filling){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - this.color=color; - this.number=number; - this.shape=shape; - this.filling=filling; - } - getAttributes(){ - 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; - } -} \ No newline at end of file diff --git a/src/Model/Card4WithoutShape.js b/src/Model/Card4WithoutShape.js deleted file mode 100644 index bf0d36c..0000000 --- a/src/Model/Card4WithoutShape.js +++ /dev/null @@ -1,27 +0,0 @@ -class Card4WithoutShape extends Card{ - constructor(color,number, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.number=number; - this.filling=filling; - this.outline=outline; - } - getAttributes(){ - return [this.number,this.color,this.filling,this.outline]; - } - equals(card){ - return this.number===card.number && this.color===card.color && this.filling===card.filling && this.outline===card.outline ; - } -} \ No newline at end of file diff --git a/src/Model/Card5.js b/src/Model/Card5.js deleted file mode 100644 index a22e47a..0000000 --- a/src/Model/Card5.js +++ /dev/null @@ -1,43 +0,0 @@ -// import('.Card'); - -class Card5 extends Card { - constructor(color, number, shape, filling, outline){ - super(); - if(color==''){ - throw new EmptyParamaterException('Color'); - } - if(number==''){ - throw new EmptyParamaterException('Number'); - } - if(shape==''){ - throw new EmptyParamaterException('Shape'); - } - if(filling==''){ - throw new EmptyParamaterException('Filling'); - } - if(outline==''){ - throw new EmptyParamaterException('Outline'); - } - this.color=color; - this.number=number; - this.shape=shape; - this.filling=filling; - this.outline=outline; - } - /** - * @returns array of all attributes : - idx 1 : color - idx 2 : number - idx 3 : shape - idx 4 : filling - idx 5 : outline - * @author Bastien Jacquelin - */ - getAttributes(){ - return [this.color,this.number,this.shape,this.filling,this.outline]; - } - equals(card){ - return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ; - } -} -// export {Card5}; \ No newline at end of file