Factory : creation of all cards done : cards of 3,4,5 attributes working, need to check to deck
continuous-integration/drone/push Build is passing Details

pull/88/head
Bastien JACQUELIN 2 years ago
parent 4951e2b8e1
commit 822b1edeba

@ -16,12 +16,6 @@
<script src="../Model/Exceptions.js"></script>
<script src="../Model/Card.js"></script>
<script src="../algo.js"></script>
<script src="../Model/Card4WithoutColor.js"></script>
<script src="../Model/Card4WithoutFilling.js"></script>
<script src="../Model/Card4WithoutNumber.js"></script>
<script src="../Model/Card4WithoutOutline.js"></script>
<script src="../Model/Card4WithoutShape.js"></script>
<script src="../Model/Card5.js"></script>
<script src="../Model/Const.js"></script>
<script src="../Model/Factory.js"></script>
<script src="../Model/Deck.js"></script>

@ -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');
/*

@ -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){

@ -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"];

@ -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<l;i++){
@ -44,7 +47,7 @@ class Factory{
* @param {*} arrayOfAttributes array
* @returns boolean
*/
inArray(i,arrayOfAttributes){
inArray(i,arrayOfAttributes){//toTest⌛
let finded=false;
for (let j=0;j<arrayOfAttributes.length;j++){
if(i==arrayOfAttributes[j]){
@ -54,12 +57,81 @@ class Factory{
return finded
}
/**
* @biref create the right cards : 3,4,5 attributes
*
* @param {*} dico dictionnary of attributes
* @returns array of the key : name of the attributes
*/
attributesName(dico){//working✅
let attributes=[]
Object.entries(dico).forEach(function([key, value]) {
attributes.push(key);
});
return attributes
}
/**
* @brief create the right cards : 3,4,5 attributes
* @param {*} arrayOfAttributes
* @param {*} length
* @returns array of all cards
*/
concreteCardCreation(attributesDico){
concreteCardCreation(){//working✅
let tabOfAllCards=[];
let dicoAttributes=this.dicoAttributes
let attributes=this.attributesName(dicoAttributes);
let nbAttributes=attributes.length;
console.log('nbAttributes',nbAttributes)
if(nbAttributes==3){
for (let c=0; c<nbAttributes; c++){
for (let n=0; n<nbAttributes; n++){
for (let s=0; s<nbAttributes; s++){
let attr1=attributes[0];
let attr2=attributes[1];
let attr3=attributes[2];
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][c],attr2:dicoAttributes[attr2][n],attr3:dicoAttributes[attr3][s]}))
}
}
}
}
else if(nbAttributes==4){
for (let a=0; a<nbAttributes; a++){
for (let b=0; b<nbAttributes; b++){
for (let c=0; c<nbAttributes; c++){
for (let d=0; d<nbAttributes; d++){
let attr1=attributes[0];
let attr2=attributes[1];
let attr3=attributes[2];
let attr4=attributes[3];
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][a],attr2:dicoAttributes[attr2][b],attr3:dicoAttributes[attr3][c],attr4:dicoAttributes[attr4][d]}))
}
}
}
}
}
else if(nbAttributes==5){
for (let a=0; a<nbAttributes; a++){
for (let b=0; b<nbAttributes; b++){
for (let c=0; c<nbAttributes; c++){
for (let d=0; d<nbAttributes; d++){
for (let e=0; e<nbAttributes; e++){
let attr1=attributes[0];
let attr2=attributes[1];
let attr3=attributes[2];
let attr4=attributes[3];
let attr5=attributes[4];
tabOfAllCards.push(new Card({attr1:dicoAttributes[attr1][a],attr2:dicoAttributes[attr2][b],attr3:dicoAttributes[attr3][c],attr4:dicoAttributes[attr4][d],attr5:dicoAttributes[attr5][e]}))
}
}
}
}
}
}
else{
throw new EmptyParamaterException("ilegal number of attributes");
}
return tabOfAllCards
}
/*
concreteCardCreation(attributesDico){//progress
let tabOfAllCards=[];
let attributes=this.attributesRequiredFun(arrayOfAttributes);
let nbAttributes=length
@ -114,5 +186,5 @@ class Factory{
throw new EmptyParamaterException("ilegal number of attributes");
}
return tabOfAllCards
}
}*/
}
Loading…
Cancel
Save