diff --git a/README.md b/README.md index ede5d5c..5624f99 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,19 @@ # HyperSet -## Description of the project - -2nd Year Project of IT BUT in Aubière +## Notes -## Subject +- [Project subject](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md) +- [Original project website](https://sancy.iut.uca.fr/~lafourcade/hyper-set-reda/HyperSet/) +## Description of the project -[link of the initial project](https://codefirst.iut.uca.fr/git/cedric.bouhours/Projets_SAE_S4/src/branch/master/Projets/Projet_11.md) +null -## Created by : +## Project Convention -LACOTE Raphaël JAULT Aurian ARNAL Rémi JACQUELIN Bastien \ No newline at end of file +- Functions names must be explicit, complete and follow **camelCase** naming +- Variable follow **camelCase** naming convention +- Opening brace must be at end of line +- Directories names my_directory +- Files names -> my_file.js +- No useless comments \ No newline at end of file diff --git a/src/Console/Console.html b/src/Console/Console.html index bc47ce5..9ba88b8 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -14,8 +14,16 @@ + + + + + + + + diff --git a/src/Console/main.js b/src/Console/main.js index 108635f..2668f88 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,20 +28,57 @@ try { } } console.groupEnd(); + + console.group('Deck'); -let deck = new Deck(); -console.log(`Output cards ${deck.outputCards}`); +let deck = new Deck([0,1,2,3]); +console.log(`All cards : ${deck.allCards.length}`); +//Display all cards +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(`All cards ${deck.allCards}`); -console.log(`Remaining cards ${deck.remainingCards}`); +// deck.setMade.forEach(e => { +// console.log(e.color,e.number,e.shape,e.filling); +// }); + +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()); +}); -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 => { +// console.log(e.color,e.number,e.shape,e.filling,e.outline); +// }); +//console.log(`Remaining cards ${deck.remainingCards}`); +//console.log(`random : ${deck.getRandCard()}`); -console.group('Maths'); -let list=[]; -list.push(1); -list.push(2); -let gngn=Math.floor(Math.random() * list.length) -console.log(gngn); console.groupEnd(); diff --git a/src/Model/Card.js b/src/Model/Card.js index d7da58b..45c5972 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -1,33 +1,15 @@ class Card{ - constructor(color, number, shape, filling){ - 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; - } + 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]; - } + 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..b1db83c --- /dev/null +++ b/src/Model/Card4WithoutOutline.js @@ -0,0 +1,27 @@ +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 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 b9d7894..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,10 @@ 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 ; } } // export {Card5}; \ No newline at end of file diff --git a/src/Model/Const.js b/src/Model/Const.js new file mode 100644 index 0000000..201e43e --- /dev/null +++ b/src/Model/Const.js @@ -0,0 +1,6 @@ +const tabColor = ['red','purple','green','blue','orange']; +const tabNumber = [1,2,3,4,5]; +const tabShape = ['diamond','oval','wave','star','triangle']; +const tabFilling = ['empty','stripped','full','pointed','squared']; +const tabOutline = ['full','dotted ','hyphen','cloudy','sharpy']; +const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline] \ No newline at end of file diff --git a/src/Model/Deck.js b/src/Model/Deck.js index b38bd49..57e9d23 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,19 +1,70 @@ class Deck{ - constructor(){ - this.outputCards=this.createDeck(); - this.setMade=[]; - this.allCards=this.createCards(); - this.remainingCards=this.allCards; + /** + * + * @param {*} attributes : array with the attributes index for the cards + */ + constructor(attributes){ + //console.log(attributes); + this.allCards=this.createCards(attributes);// All the cards in the game + 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(); } + /** + * @brief creation of the deck : call factory to create the good cards + */ createDeck(){ for (let i=0; i<12; i++){ - + const rand = this.getRandCard(); + this.outputCards.push(this.remainingCards[rand]); + this.remainingCards.splice(rand,1); } } + /** + * + * @returns random number in range of the array size + */ getRandCard(){ - Math.floor(Math.random() * remainingCards.length); + const random = Math.floor(Math.random() * this.remainingCards.length); + return random; } - createCards(){ - return 456; + /** + * + * @param attributes : index of the attributes used + * @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes + */ + createCards(attributes){ + let factory = new Factory(attributes) + return factory.product + } + checkSet(selectedCards){ + if(true){//isSet(selectedCards)){ + selectedCards.forEach(e => { + this.removeFromoutputCards(e); + }); + } + } + /** + * + * @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards + */ + removeFromoutputCards(selectedCards){//better check of card type more opti + let set=[]; + for(let i=0; i) + * { + * new array> matrice = vide + * + * forEach(array: value) + * { + * matrice.add(value.getAttrib) + * } + * Check all length of matrice + * for(i = 0; i tab + * for (j=0; j { + attributesMatrix.push(element.getAttributes()); + }); + // Idéalement check si toute les listes d'attributs sont de même taille + for(let i = 0; i < attributesMatrix[0].length; i++) { + let listAttributes = [] + for(let j = 0; j < attributesMatrix.length; j++) { + listAttributes.push(attributesMatrix[j][i]); + } + if(!checkAttributes(listAttributes)){ + return false; + } + } + return true; +} + + +function checkAttributes(attributes){ + let orderingMethod = "null"; // Can only take ["null", "same", "different"] + let boolLoop = true; + attributes.forEach((value, index) => { + if(index !== attributes.length) + { + for (let i = index+1; i < attributes.length; i++) + { + if(attributes[i] === value) + { + if(orderingMethod === "null" || orderingMethod === "same") + { + orderingMethod = "same"; + } + else + { + boolLoop = false; + } + } + else + { + if(orderingMethod === "null" || orderingMethod === "different") + { + orderingMethod = "different" + } + else + { + boolLoop = false + } + } + + } + } + }); + return boolLoop === true; +}