From 99ed8b123307f587a7d356c4367cae42747a0205 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Mon, 6 Feb 2023 17:30:44 +0100 Subject: [PATCH] add all class of 4 attributes cards, edit facotry --- src/Console/Console.html | 6 +++ src/Console/main.js | 23 +++++---- src/Model/Card.js | 45 ++++-------------- 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 | 23 +++++++-- src/Model/Deck.js | 68 ++++++++------------------ src/Model/Factory.js | 82 ++++++++++++++++++++++++++++++++ src/index.html | 20 -------- 12 files changed, 286 insertions(+), 116 deletions(-) create mode 100644 src/Model/Card4WithoutColor.js create mode 100644 src/Model/Card4WithoutFilling.js create mode 100644 src/Model/Card4WithoutNumber.js create mode 100644 src/Model/Card4WithoutOutline.js create mode 100644 src/Model/Card4WithoutShape.js create mode 100644 src/Model/Factory.js delete mode 100644 src/index.html diff --git a/src/Console/Console.html b/src/Console/Console.html index f639d2a..9ba88b8 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -16,8 +16,14 @@ + + + + + + diff --git a/src/Console/main.js b/src/Console/main.js index b0652e6..2374db8 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -3,12 +3,14 @@ //import {Card} from '../Model/Card'; console.log("~#Test#~"); -let card4 = new Card('red','2','losange','full'); +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]}`); @@ -26,19 +28,22 @@ try { } } console.groupEnd(); -console.group('Deck'); -let deck = new Deck([0,1,2,3],4); + +console.group('Deck'); +let deck = new Deck([0,1,2,3]); console.log(`All cards with 4 attributes size ${deck.allCards.length}`); console.log(`size output ${deck.outputCards.length}`); -// Display all cards -// deck.allCards.forEach(e => { -// console.log(e.color,e.number,e.shape,e.filling); -// }); -console.log(`Output cards`); -deck.outputCards.forEach(e => { +//Display all cards +console.log(`All cards`); +console.log(deck.allCards) +deck.allCards.forEach(e => { console.log(e.color,e.number,e.shape,e.filling); }); +console.log(`Output cards`); +// deck.outputCards.forEach(e => { +// console.log(e.getAttributes()); +// }); console.log(`set already made ${deck.setMade}`); diff --git a/src/Model/Card.js b/src/Model/Card.js index 3ee1a44..45c5972 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,40 +1,15 @@ class Card{ - constructor(color, number, shape, filling, outline){ - 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; - } + constructor(){} /** - * @returns array of all attributes : - idx 1 : color - idx 2 : number - idx 3 : shape - idx 4 : filling - idx 5 : null - * @author Bastien Jacquelin + * + * @returns all attributes of a card */ - 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 ; - } + getAttributes(){} + /** + * + * @param {*} card card to be compared with the current obj + * @returns boolean + */ + equals(card){} }//export {Card} \ No newline at end of file diff --git a/src/Model/Card4WithoutColor.js b/src/Model/Card4WithoutColor.js new file mode 100644 index 0000000..cbad689 --- /dev/null +++ b/src/Model/Card4WithoutColor.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..b895c07 --- /dev/null +++ b/src/Model/Card4WithoutFilling.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..95abc61 --- /dev/null +++ b/src/Model/Card4WithoutNumber.js @@ -0,0 +1,27 @@ +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 new file mode 100644 index 0000000..c52c2f1 --- /dev/null +++ b/src/Model/Card4WithoutOutline.js @@ -0,0 +1,27 @@ +class Card4WithoutOutline extends Card{ + constructor(color, number, shape, filling){ + super(); + if(number==''){ + throw new EmptyParamaterException('Number'); + } + if(shape==''){ + throw new EmptyParamaterException('Shape'); + } + if(filling==''){ + throw new EmptyParamaterException('Filling'); + } + if(color==''){ + throw new EmptyParamaterException('Color'); + } + this.number=number; + this.shape=shape; + this.filling=filling; + this.color=color; + } + getAttributes(){ + return [this.number,this.shape,this.filling,this.color]; + } + 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 new file mode 100644 index 0000000..bf0d36c --- /dev/null +++ b/src/Model/Card4WithoutShape.js @@ -0,0 +1,27 @@ +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 index bead780..a22e47a 100644 --- a/src/Model/Card5.js +++ b/src/Model/Card5.js @@ -2,10 +2,26 @@ class Card5 extends Card { constructor(color, number, shape, filling, outline){ - super(color,number,shape,filling); - if(!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; } /** @@ -18,8 +34,7 @@ class Card5 extends Card { * @author Bastien Jacquelin */ getAttributes(){ - // return [this.color,this.number,this.shape,this.filling,this.outline]; - return super.getAttributes().concat(this.outline); + 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 ; diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 40c365c..1c13a92 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -3,38 +3,17 @@ class Deck{ * * @param {*} attributes : array with the attributes index for the cards */ - constructor(attributes,nbAttributes){ - let attributesRequired=this.attributesRequiredFun(attributes); - attributesRequired.forEach(e=>{ - for(let i=0;i - - - - - My awesome blog - - - -

My awesome blog

- - - - - - - - \ No newline at end of file