From 18a3c1281f71d20dbec3d474720aa10bfc2cffd2 Mon Sep 17 00:00:00 2001 From: Bastien Jacquelin Date: Mon, 6 Mar 2023 20:00:17 +0100 Subject: [PATCH] pb on deck, on creation of the deck --- src/Console/main.js | 34 +++++++++++------- src/Model/Deck.js | 63 +++++++++++++++++--------------- src/Model/Factory.js | 85 ++++++++------------------------------------ src/algo.js | 6 ++-- 4 files changed, 74 insertions(+), 114 deletions(-) diff --git a/src/Console/main.js b/src/Console/main.js index ff491bf..650495b 100644 --- a/src/Console/main.js +++ b/src/Console/main.js @@ -1,7 +1,3 @@ -// import { Card5 } from "../Model/Card5"; -// import('../Model/Card5'); -//import {Card} from '../Model/Card'; - console.log("~#Test#~"); console.group('Card');//DONE @@ -18,17 +14,33 @@ console.log(card1.equals(card3));//FALSE console.log(card1.equals(card4));//FALSE */ console.groupEnd(); - - console.group('Factory'); console.log('Passed') -let fact3=new Factory([0,1,2]); -let fact4=new Factory([0,1,2,3]); -let fact5=new Factory([0,1,2,3,4]); +// let fact3=new Factory([0,1,2]); +let fact4=new Factory([0,1,2,3],3); +//console.log(fact4.attributesDictionnary); +// let fact5=new Factory([0,1,2,3,4]); console.groupEnd(); -// CREATE DECK console.group('Deck'); +let deck = new Deck([0,1,2,3],3); +console.log("allCards",deck.allCards); +console.log("allCards.length",deck.allCards.length); +console.log("remainingCards.length",deck.remainingCards.length); +console.log("outputCards",deck.outputCards); +console.group("checkSet"); + +console.log("outputCards 0",deck.outputCards[0]); +console.log("outputCards",deck.outputCards); + +console.log("allCards",deck.allCards[0]); +console.log("remainingCards",deck.remainingCards[0]); + +console.log(deck.checkSet([deck.outputCards[0],deck.outputCards[1],deck.outputCards[2]])); +console.log("remainingCards.length",deck.remainingCards.length); +console.log("outputCards",deck.outputCards); +console.groupEnd(); + /* console.log("~~BEGINNING~~"); let deck = new Deck([0,1,2,3],3); @@ -87,8 +99,6 @@ console.groupEnd(); //console.log(`Remaining cards ${deck.remainingCards}`); //console.log(`random : ${deck.getRandCard()}`); -console.groupEnd(); - // CHECK SET // console.log("~~CHECKING ALL SET~~") diff --git a/src/Model/Deck.js b/src/Model/Deck.js index 8b0c280..f3df37c 100644 --- a/src/Model/Deck.js +++ b/src/Model/Deck.js @@ -5,22 +5,35 @@ class Deck{ * @author Bastien Jacquelin */ constructor(attributes,nbCards){ - //console.log(attributes); + this.nbCards=nbCards;// number of card to do a set this.allCards=this.createCards(attributes);// All the cards in the game - this.remainingCards=[] - this.nbCards=nbCards; - this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack + this.remainingCards=[];//init tab null + this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack, init = all before creation of deck -> remove this.outputCards=[];// 12 cards lay on the table this.setMade=[];// array of array with all the set already mades (array of set) this.createDeck(12); + console.log("nbCards",this.nbCards); + // console.log("allCards after deck",this.allCards); + console.log("remainingCards after deck",this.remainingCards); + console.log("outputCards",this.outputCards); + console.log("setMade",this.setMade); + } + /** + * + * @param attributes : index of the attributes used + * @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes + * @author Bastien Jacquelin + */ + createCards(attributes){//working✅ + let factory = new Factory(attributes,this.nbCards); + return factory.product; } - /** - * @brief creation of the deck : 12 cards lay in front of the player + * @brief creation of the deck : 12 random cards lay in front of the player * @author Bastien Jacquelin */ - createDeck(nbCards){ - if(this.remainingCards.length==0){ + createDeck(nbCards){//toTest⌛ + if(this.remainingCards.length { for(let i=0; i { for (let i=0;i