From 822b1edeba81f44a5fce90744dc73dd975ffbd74 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Mar 2023 12:26:18 +0100 Subject: [PATCH] Factory : creation of all cards done : cards of 3,4,5 attributes working, need to check to deck --- src/Console/Console.html | 6 --- src/Console/main.js | 6 +++ src/Model/Card.js | 4 +- src/Model/Const.js | 2 +- src/Model/Factory.js | 90 ++++++++++++++++++++++++++++++++++++---- 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/src/Console/Console.html b/src/Console/Console.html index 23876d4..68b4247 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -16,12 +16,6 @@ - - - - - - diff --git a/src/Console/main.js b/src/Console/main.js index 8e34e15..40cfa0e 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -20,6 +20,12 @@ console.log(card1.equals(card4));//FALSE console.groupEnd(); +console.group('Factory'); +let fact3=new Factory([0,1,2]); +let fact4=new Factory([0,1,2,3]); +let fact5=new Factory([0,1,2,3,4]); +console.groupEnd(); + // CREATE DECK console.group('Deck'); /* diff --git a/src/Model/Card.js b/src/Model/Card.js index 9420f3f..864bac6 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -10,7 +10,7 @@ class Card{ * * @returns all attributes of a card */ - getAttributes(){ + getAttributes(){//working✅ let att=[]; Object.entries(this.attributes).forEach(function([key, value]) { att.push(value); @@ -22,7 +22,7 @@ class Card{ * @param {*} card card to be compared with the current obj * @returns boolean */ - equals(card){ + equals(card){//working✅ let bool=true; Object.entries(this.attributes).forEach(function([key, value]) { if(card.attributes[key]!=value){ diff --git a/src/Model/Const.js b/src/Model/Const.js index 4337dcf..3fae447 100644 --- a/src/Model/Const.js +++ b/src/Model/Const.js @@ -2,6 +2,6 @@ const TAB_COLOR = ['red','purple','green','blue','orange']; const TAB_NUMBER = [1,2,3,4,5]; const TAB_SHAPE = ['diamond','oval','wave','star','triangle']; const TAB_FILLING = ['empty','stripped','full','pointed','squared']; -const TAB_OUTLINE = ['full','dotted','hyphen','cloudy','sharpy']; +const TAB_OUTLINE = ['continuous','dotted','hyphen','cloudy','sharpy']; const ATTRIBUTES=[TAB_COLOR,TAB_NUMBER,TAB_SHAPE,TAB_FILLING,TAB_OUTLINE]; const IDX_ATTRIBUTES=["color","number","shape","filling","outline"]; \ No newline at end of file diff --git a/src/Model/Factory.js b/src/Model/Factory.js index 1ff8c0e..3519386 100644 --- a/src/Model/Factory.js +++ b/src/Model/Factory.js @@ -1,16 +1,19 @@ class Factory{ constructor(arrayOfAttributes){ - let length=arrayOfAttributes.length - this.product=this.concreteCardCreation(arrayOfAttributes); + this.dicoAttributes=this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes)); console.log("arrayOfAttributes",this.funArrayOfAttributes(arrayOfAttributes)); - console.log("attributesDictionnary",this.attributesDictionnary(arrayOfAttributes,this.funArrayOfAttributes(arrayOfAttributes))) + console.log("attributesDictionnary",this.dicoAttributes) + console.log("attributesName",this.attributesName(this.dicoAttributes)); + this.product=this.concreteCardCreation(arrayOfAttributes); + console.log("allCards",this.product); + } /** * * @param {*} arrayOfIdxAttributes index of attributes in ATTRIBUTES * @returns array of all attributes */ - funArrayOfAttributes(arrayOfIdxAttributes){ + funArrayOfAttributes(arrayOfIdxAttributes){//working✅ let attr=[]; let l=arrayOfIdxAttributes.length; arrayOfIdxAttributes.forEach(e => { @@ -26,7 +29,7 @@ class Factory{ * @param {*} arrayOfAllAttributes array of all attributes * @returns dictionnary with key : attribute and value : array of the possibilities of attributes */ - attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){ + attributesDictionnary(arrayOfIdxAttributes,arrayOfAllAttributes){//working✅ let l=arrayOfIdxAttributes.length; let dico={}; for (let i=0;i