From 7450bb88776b10708d8096b017c3930667ccb481 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Feb 2023 12:09:13 +0100 Subject: [PATCH 1/5] create cards and deck --- src/Console/main.js | 36 +++++++++++++++++++++++++----------- src/Model/Deck.js | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 60 insertions(+), 20 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 108635f..930cf2c 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -27,19 +27,33 @@ try { } console.groupEnd(); console.group('Deck'); -let deck = new Deck(); -console.log(`Output cards ${deck.outputCards}`); +let deck = new Deck(4); + +console.log(`All cards with 4 attributes size ${deck.allCards.length}`); +console.log(`size ${deck.outputCards.length}`); + +// 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.color,e.number,e.shape,e.filling); +}); console.log(`set already made ${deck.setMade}`); -console.log(`All cards ${deck.allCards}`); -console.log(`Remaining cards ${deck.remainingCards}`); -console.groupEnd(); -console.group('Maths'); -let list=[]; -list.push(1); -list.push(2); -let gngn=Math.floor(Math.random() * list.length) -console.log(gngn); + + + +let deck5 = new Deck(5) +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.groupEnd(); diff --git a/src/Model/Deck.js b/src/Model/Deck.js index b38bd49..55d34bd 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,19 +1,45 @@ class Deck{ - constructor(){ - this.outputCards=this.createDeck(); - this.setMade=[]; - this.allCards=this.createCards(); - this.remainingCards=this.allCards; + constructor(nbAttributes){ + this.allCards=this.createCards(nbAttributes);// All the cards in the game + this.remainingCards=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(); } createDeck(){ for (let i=0; i<12; i++){ - + const rand = this.getRandCard(); + this.outputCards.push(this.remainingCards[rand]); + this.remainingCards.splice(rand,1); } } getRandCard(){ - Math.floor(Math.random() * remainingCards.length); + const random = Math.floor(Math.random() * this.remainingCards.length); + return random; } - createCards(){ - return 456; + createCards(nbAttributes){ + const tabColor = ['red','purple','green','blue','orange']; + const tabShape = ['diamond','oval','wave','star','circle'] + const tabFilling = ['empty','stripped','full','pointed','squared']; + const tabNumber = [1,2,3,4,5]; + const tabOutline = ['full','dotted ','aa','bb','cc']; + let tabOfAllCards=[]; + for (let c=0; c Date: Thu, 2 Feb 2023 14:19:54 +0100 Subject: [PATCH 2/5] add unfoundCardException, add the set verificatio operations --- src/Console/Console.html | 1 + src/Model/Deck.js | 29 ++++++++++++++++++++++++++++- src/Model/unfoundCardException.js | 5 +++++ 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/Model/unfoundCardException.js diff --git a/src/Console/Console.html b/src/Console/Console.html index bc47ce5..1f6b5c3 100644 --- a/src/Console/Console.html +++ b/src/Console/Console.html @@ -14,6 +14,7 @@ + diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 55d34bd..81ee4e8 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -1,5 +1,5 @@ class Deck{ - constructor(nbAttributes){ + constructor(nbAttributes=4){ this.allCards=this.createCards(nbAttributes);// All the cards in the game this.remainingCards=this.allCards;// cards in the stack this.outputCards=[];// 12 cards lay on the table @@ -17,6 +17,11 @@ class Deck{ const random = Math.floor(Math.random() * this.remainingCards.length); return random; } + /** + * + * @param {*} nbAttributes : attributes of the card, by default = 4 + * @returns all cards: 81 in case of 4 attributes and 1224 + */ createCards(nbAttributes){ const tabColor = ['red','purple','green','blue','orange']; const tabShape = ['diamond','oval','wave','star','circle'] @@ -42,4 +47,26 @@ class Deck{ } return tabOfAllCards; } + checkSet(selectedCards){ + if(true){//isSet(selectedCards)){ + selectedCards.forEach(e => { + this.removeFromRemainingCards(e); + }); + } + } + removeFromRemainingCards(selectedCards){ + let set=[]; + if (selectedCards instanceof Card) { + for(let i=0; i Date: Thu, 2 Feb 2023 14:29:59 +0100 Subject: [PATCH 3/5] update README.md --- README.md | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index ede5d5c..246a05b 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 and complete +- 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 From 1dfdae926e8103f47855a44031a5d5d699e1f4f9 Mon Sep 17 00:00:00 2001 From: RemRem Date: Thu, 2 Feb 2023 14:32:17 +0100 Subject: [PATCH 4/5] update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 246a05b..5624f99 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ null ## Project Convention -- Functions names must be explicit and complete +- 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 From 0add9526fe5fc2450a2dbcd5e4cb95bd82db2d02 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Thu, 2 Feb 2023 15:16:23 +0100 Subject: [PATCH 5/5] remove from deck set cards --- src/Console/main.js | 19 +++++++++++++++---- src/Model/Card.js | 3 +++ src/Model/Card5.js | 3 +++ src/Model/Deck.js | 30 ++++++++++++++++-------------- src/Model/unfoundCardException.js | 4 ++-- 5 files changed, 39 insertions(+), 20 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index 930cf2c..a349a7b 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -41,10 +41,19 @@ deck.outputCards.forEach(e => { }); console.log(`set already made ${deck.setMade}`); - - - - +deck.allCards.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); + }); +let customCard=[new Card('red',1,'diamond','stripped')]; +deck.checkSet(customCard); +console.log(`deck size :${deck.allCards.length}`); +deck.allCards.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); +}); +console.log(`remaining cars:`); +deck.setMade.forEach(e => { + console.log(e.color,e.number,e.shape,e.filling); + }); let deck5 = new Deck(5) console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); @@ -56,4 +65,6 @@ console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); + + console.groupEnd(); diff --git a/src/Model/Card.js b/src/Model/Card.js index d7da58b..0b8997b 100644 --- a/src/Model/Card.js +++ b/src/Model/Card.js @@ -29,5 +29,8 @@ class Card{ getAttributes(){ return [this.color,this.number,this.shape,this.filling]; } + equals(card){ + return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling; + } }//export {Card} \ No newline at end of file diff --git a/src/Model/Card5.js b/src/Model/Card5.js index b9d7894..bead780 100644 --- a/src/Model/Card5.js +++ b/src/Model/Card5.js @@ -21,5 +21,8 @@ class Card5 extends Card { // return [this.color,this.number,this.shape,this.filling,this.outline]; return super.getAttributes().concat(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/Deck.js b/src/Model/Deck.js index 81ee4e8..5be6949 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -4,7 +4,7 @@ class Deck{ this.remainingCards=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(); + //this.createDeck(); } createDeck(){ for (let i=0; i<12; i++){ @@ -24,9 +24,9 @@ class Deck{ */ createCards(nbAttributes){ const tabColor = ['red','purple','green','blue','orange']; - const tabShape = ['diamond','oval','wave','star','circle'] - const tabFilling = ['empty','stripped','full','pointed','squared']; const tabNumber = [1,2,3,4,5]; + const tabShape = ['diamond','oval','wave','star','circle']; + const tabFilling = ['empty','stripped','full','pointed','squared']; const tabOutline = ['full','dotted ','aa','bb','cc']; let tabOfAllCards=[]; for (let c=0; c