deck create, remove the cards from the last one

pull/32/head
Bastien JACQUELIN 2 years ago
parent 77665d9254
commit 889c843aa7

@ -31,28 +31,46 @@ console.groupEnd();
console.group('Deck'); console.group('Deck');
let deck = new Deck([0,1,3,4]); let deck = new Deck([0,1,2,3]);
console.log(`All cards with 4 attributes size ${deck.allCards.length}`); console.log(`All cards : ${deck.allCards.length}`);
console.log(`size output ${deck.outputCards.length}`);
//Display all cards //Display all cards
console.log(`All cards`); console.log(`All cards display`);
deck.allCards.forEach(e => { // deck.allCards.forEach(e => {
//console.log(e.color,e.number,e.shape,e.filling); // console.log(e.color,e.number,e.shape,e.filling);//no outline
console.log(e.color,e.number,e.filling,e.outline); // //console.log(e.color,e.number,e.filling,e.outline);//no shape
//console.log(e.color,e.number,e.shape,e.outline); // //console.log(e.color,e.number,e.shape,e.outline);//no filling
}); // });
console.log(`Output cards`); console.log(`remaining cards : ${deck.remainingCards.length}`)
// deck.outputCards.forEach(e => { // deck.remainingCards.forEach(e => {
// console.log(e.getAttributes()); // 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(`set already made ${deck.setMade}`);
console.log(`remaining cards:`); // deck.setMade.forEach(e => {
deck.setMade.forEach(e => { // console.log(e.color,e.number,e.shape,e.filling);
console.log(e.color,e.number,e.shape,e.filling); // });
});
let customCard=[new Card('red',1,'diamond','stripped')]; console.log("Card to remove: ")
//deck.checkSet(customCard); 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());
});
//let deck5 = new Deck([0,1,2,3,4]); //let deck5 = new Deck([0,1,2,3,4]);

@ -1,6 +1,9 @@
class Card4WithoutOutline extends Card{ class Card4WithoutOutline extends Card{
constructor(color, number, shape, filling){ constructor(color, number, shape, filling){
super(); super();
if(color==''){
throw new EmptyParamaterException('Color');
}
if(number==''){ if(number==''){
throw new EmptyParamaterException('Number'); throw new EmptyParamaterException('Number');
} }
@ -10,16 +13,13 @@ class Card4WithoutOutline extends Card{
if(filling==''){ if(filling==''){
throw new EmptyParamaterException('Filling'); throw new EmptyParamaterException('Filling');
} }
if(color==''){ this.color=color;
throw new EmptyParamaterException('Color');
}
this.number=number; this.number=number;
this.shape=shape; this.shape=shape;
this.filling=filling; this.filling=filling;
this.color=color;
} }
getAttributes(){ getAttributes(){
return [this.number,this.shape,this.filling,this.color]; return [this.color,this.number,this.shape,this.filling];
} }
equals(card){ equals(card){
return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.color===card.color; return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.color===card.color;

@ -4,9 +4,10 @@ class Deck{
* @param {*} attributes : array with the attributes index for the cards * @param {*} attributes : array with the attributes index for the cards
*/ */
constructor(attributes){ constructor(attributes){
console.log(attributes); //console.log(attributes);
this.allCards=this.createCards(attributes);// All the cards in the game this.allCards=this.createCards(attributes);// All the cards in the game
this.remainingCards=this.allCards;// cards in the stack this.remainingCards=[]
this.remainingCards=this.remainingCards.concat(this.allCards);// cards in the stack
this.outputCards=[];// 12 cards lay on the table this.outputCards=[];// 12 cards lay on the table
this.setMade=[];// array with all the set already mades (array of set) this.setMade=[];// array with all the set already mades (array of set)
this.createDeck(); this.createDeck();
@ -41,7 +42,7 @@ class Deck{
checkSet(selectedCards){ checkSet(selectedCards){
if(true){//isSet(selectedCards)){ if(true){//isSet(selectedCards)){
selectedCards.forEach(e => { selectedCards.forEach(e => {
this.removeFromRemainingCards(e); this.removeFromoutputCards(e);
}); });
} }
} }
@ -49,13 +50,13 @@ class Deck{
* *
* @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards * @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards
*/ */
removeFromRemainingCards(selectedCards){//better check of card type more opti removeFromoutputCards(selectedCards){//better check of card type more opti
let set=[]; let set=[];
for(let i=0; i<this.allCards.length;i++){ for(let i=0; i<this.outputCards.length;i++){
let e = this.allCards[i] let e = this.outputCards[i]
if(e.equals(selectedCards)){ if(e.equals(selectedCards)){
set.push(e); set.push(e);
this.allCards.splice(i,1); this.outputCards.splice(i,1);
console.log("card remove : "+e.color,e.number,e.filling,e.shape); console.log("card remove : "+e.color,e.number,e.filling,e.shape);
} }
} }

@ -3,27 +3,26 @@ class Factory{
let length=arrayOfAttributes.length let length=arrayOfAttributes.length
this.product=this.concreteCardCreation(arrayOfAttributes,length); this.product=this.concreteCardCreation(arrayOfAttributes,length);
} }
inArray(i,arrayOfAttributes){
let finded=false;
for (let j=0;j<arrayOfAttributes.length;j++){
if(i==arrayOfAttributes[j]){
finded=true;
}
}
return finded
}
attributesRequiredFun(arrayOfAttributes,length){ attributesRequiredFun(arrayOfAttributes,length){
console.log("arr attr")
console.log(arrayOfAttributes)
let attributesRequiredTmp=[]; let attributesRequiredTmp=[];
let nullArray=[0,0,0,0,0]; let nullArray=[0,0,0,0,0];
for(let i=0;i<5;i++){ for(let i=0;i<5;i++){
let find=false; if(!this.inArray(i,arrayOfAttributes)){
for (let j=0;j<length;j++){
if(i==arrayOfAttributes[j]){
attributesRequiredTmp.push(ATTRIBUTES[j]);
find=true;
}
}
if(!find){
attributesRequiredTmp.push(nullArray); attributesRequiredTmp.push(nullArray);
} }
else{
attributesRequiredTmp.push(ATTRIBUTES[i]);
}
} }
attributesRequiredTmp.forEach(e=>{
console.log("tab index")
console.log(e);
});
return attributesRequiredTmp; return attributesRequiredTmp;
} }
concreteCardCreation(arrayOfAttributes, length){ concreteCardCreation(arrayOfAttributes, length){
@ -51,7 +50,6 @@ class Factory{
tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o])); tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o]));
} }
else if(attributes[2][0]===0){ else if(attributes[2][0]===0){
console.log("jrentre la frro")
tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o])); tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o]));
} }
else if(attributes[3][0]===0){ else if(attributes[3][0]===0){

Loading…
Cancel
Save