remove from deck set cards

pull/37/head
Bastien JACQUELIN 2 years ago
parent 07e116ed0f
commit 0add9526fe

@ -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();

@ -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}

@ -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};

@ -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<nbAttributes-1; c++){
@ -54,19 +54,21 @@ class Deck{
});
}
}
removeFromRemainingCards(selectedCards){
removeFromRemainingCards(selectedCards){//better check of card type more opti
let set=[];
if (selectedCards instanceof Card) {
for(let i=0; i<this.remainingCards.length;i++){
let e = this.remainingCards[i]
if(e.color==selectedCards.color||e.number==selectedCards.number||e.shape==selectedCards.shape||e.filling==selectedCards.filling){
set.push[e];
this.remainingCards.splice(i,1);
for(let i=0; i<this.allCards.length;i++){
let e = this.allCards[i]
if(e.equals(selectedCards)){
set.push(e);
this.allCards.splice(i,1);
console.log("card remove : "+e.color,e.number,e.filling,e.shape);
}
else{
throw new UnFoundCard(e);
}
if(set.length!=1){
throw new UnFoundCardException(selectedCards);
}
else{
this.setMade.push(set);
}
}
}

@ -1,5 +1,5 @@
class UnFoundCard extends Error(){
class UnFoundCardException extends Error{
constructor(card){
super(`Card ${card.color, card.shape, card.number, card.filling} is missing`);
super(`Card ${card.color +" "+ card.shape+ " " + card.number +" "+ card.filling} is missing`);
}
}
Loading…
Cancel
Save