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');
let deck = new Deck([0,1,3,4]);
console.log(`All cards with 4 attributes size ${deck.allCards.length}`);
console.log(`size output ${deck.outputCards.length}`);
let deck = new Deck([0,1,2,3]);
console.log(`All cards : ${deck.allCards.length}`);
//Display all cards
console.log(`All cards`);
deck.allCards.forEach(e => {
//console.log(e.color,e.number,e.shape,e.filling);
console.log(e.color,e.number,e.filling,e.outline);
//console.log(e.color,e.number,e.shape,e.outline);
});
console.log(`Output cards`);
// deck.outputCards.forEach(e => {
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(`remaining cards:`);
deck.setMade.forEach(e => {
console.log(e.color,e.number,e.shape,e.filling);
});
// deck.setMade.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("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());
});
//let deck5 = new Deck([0,1,2,3,4]);

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

@ -4,9 +4,10 @@ class Deck{
* @param {*} attributes : array with the attributes index for the cards
*/
constructor(attributes){
console.log(attributes);
//console.log(attributes);
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.setMade=[];// array with all the set already mades (array of set)
this.createDeck();
@ -41,7 +42,7 @@ class Deck{
checkSet(selectedCards){
if(true){//isSet(selectedCards)){
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
*/
removeFromRemainingCards(selectedCards){//better check of card type more opti
removeFromoutputCards(selectedCards){//better check of card type more opti
let set=[];
for(let i=0; i<this.allCards.length;i++){
let e = this.allCards[i]
for(let i=0; i<this.outputCards.length;i++){
let e = this.outputCards[i]
if(e.equals(selectedCards)){
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);
}
}

@ -3,27 +3,26 @@ class Factory{
let length=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){
console.log("arr attr")
console.log(arrayOfAttributes)
let attributesRequiredTmp=[];
let nullArray=[0,0,0,0,0];
for(let i=0;i<5;i++){
let find=false;
for (let j=0;j<length;j++){
if(i==arrayOfAttributes[j]){
attributesRequiredTmp.push(ATTRIBUTES[j]);
find=true;
}
}
if(!find){
if(!this.inArray(i,arrayOfAttributes)){
attributesRequiredTmp.push(nullArray);
}
else{
attributesRequiredTmp.push(ATTRIBUTES[i]);
}
}
attributesRequiredTmp.forEach(e=>{
console.log("tab index")
console.log(e);
});
return attributesRequiredTmp;
}
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]));
}
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]));
}
else if(attributes[3][0]===0){

Loading…
Cancel
Save