card class only, can take multiple attributes, deck and card creation to do
continuous-integration/drone/push Build is passing Details

pull/88/head
Bastien JACQUELIN 2 years ago
parent 65f1bab97b
commit 4951e2b8e1

@ -3,36 +3,26 @@
//import {Card} from '../Model/Card';
console.log("~#Test#~");
let card4 = new Card4WithoutOutline('red','2','losange','full');
console.group('Carte 4 attributes');
console.log(`carte de 4 elements : ${card4.color}`);
console.groupEnd();
let card5 = new Card5('blue','2','losange','full','pointillet');
console.group('Carte 5 attributes');
console.log(`carte de 5 elements : ${card5.color}`);
console.log(`carte de 5 elements : ${card5.outline}`);
console.log(`carte de 5 éléments instance de 5: ${card5 instanceof Card5}`);
console.log(`carte de 5 éléments accès par méthode idx 0: ${card5.getAttributes()[0]}`);
console.log(`carte de 5 éléments accès par méthode idx 4: ${card5.getAttributes()[4]}`);
console.groupEnd();
console.group('Error');
try {
let errCard = new Card5('blue','','losange','full','pointillet');
}catch(errCard){
if(errCard instanceof EmptyParamaterException){
console.log('Error in constructor');
}
else{
console.error(errCard);
}
}
console.group('Card');//DONE
console.log('Passed')
/*
let card1=new Card({'color':'red','filling':'full'});
let card2=new Card({'color':'red','filling':'full'});
let card3=new Card({'color':'red','outline':'full'});
let card4=new Card({'color':'red','filling':'empty'});
console.log(card1.attributes);// ATTRIBUTES
console.log(card1.getAttributes());// ATTRIBUTES
console.log(card1.equals(card2));// TRUE
console.log(card1.equals(card3));//FALSE
console.log(card1.equals(card4));//FALSE
*/
console.groupEnd();
// CREATE DECK
console.group('Deck');
/*
console.log("~~BEGINNING~~");
let deck = new Deck([0,1,2,3],3);
console.log(`All cards : ${deck.allCards.length}`);
@ -80,8 +70,8 @@ deck.setMade.forEach(e => {//tab of tab of cards of set made
})
});
// console.log(deck.setMade)
*/
console.groupEnd();
//let deck5 = new Deck([0,1,2,3,4]);
//console.log(`All cards with 5 attributes size ${deck5.allCards.length}`);
// deck5.allCards.forEach(e => {

@ -1,25 +1,34 @@
class Card{
/**
*
* @param {*} attributes : dictionnary of attributes : key : name of the attributes and value : value of the attributes
*/
constructor(attributes){
this.attributes=attributes;
}
createAttributes(arrayOfAttributes){
}
/**
*
* @returns all attributes of a card
*/
getAttributes(){}
getAttributes(){
let att=[];
Object.entries(this.attributes).forEach(function([key, value]) {
att.push(value);
});
return att;
}
/**
*
* @param {*} card card to be compared with the current obj
* @returns boolean
*/
equals(card){}
}//export {Card}
equals(card){
let bool=true;
Object.entries(this.attributes).forEach(function([key, value]) {
if(card.attributes[key]!=value){
bool=false;
}
});
return bool;
}
}

@ -1,27 +0,0 @@
class Card4WithoutColor extends Card{
constructor(number, shape, filling, outline){
super();
if(number==''){
throw new EmptyParamaterException('Number');
}
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(filling==''){
throw new EmptyParamaterException('Filling');
}
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.number=number;
this.shape=shape;
this.filling=filling;
this.outline=outline;
}
getAttributes(){
return [this.number,this.shape,this.filling,this.outline];
}
equals(card){
return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ;
}
}

@ -1,27 +0,0 @@
class Card4WithoutFilling extends Card{
constructor(color,number, shape, outline){
super();
if(number==''){
throw new EmptyParamaterException('Number');
}
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(color==''){
throw new EmptyParamaterException('Color');
}
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.number=number;
this.shape=shape;
this.color=color;
this.outline=outline;
}
getAttributes(){
return [this.number,this.shape,this.color,this.outline];
}
equals(card){
return this.number===card.number && this.shape===card.shape && this.color===card.color && this.outline===card.outline ;
}
}

@ -1,27 +0,0 @@
class Card4WithoutNumber extends Card{
constructor(color, shape, filling, outline){
super();
if(color==''){
throw new EmptyParamaterException('Color');
}
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(filling==''){
throw new EmptyParamaterException('Filling');
}
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.color=color;
this.shape=shape;
this.filling=filling;
this.outline=outline;
}
getAttributes(){
return [this.color,this.shape,this.filling,this.outline];
}
equals(card){
return this.color===card.color && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ;
}
}

@ -1,27 +0,0 @@
class Card4WithoutOutline extends Card{
constructor(color, number, shape, filling){
super();
if(color==''){
throw new EmptyParamaterException('Color');
}
if(number==''){
throw new EmptyParamaterException('Number');
}
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(filling==''){
throw new EmptyParamaterException('Filling');
}
this.color=color;
this.number=number;
this.shape=shape;
this.filling=filling;
}
getAttributes(){
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;
}
}

@ -1,27 +0,0 @@
class Card4WithoutShape extends Card{
constructor(color,number, filling, outline){
super();
if(color==''){
throw new EmptyParamaterException('Color');
}
if(number==''){
throw new EmptyParamaterException('Number');
}
if(filling==''){
throw new EmptyParamaterException('Filling');
}
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.color=color;
this.number=number;
this.filling=filling;
this.outline=outline;
}
getAttributes(){
return [this.number,this.color,this.filling,this.outline];
}
equals(card){
return this.number===card.number && this.color===card.color && this.filling===card.filling && this.outline===card.outline ;
}
}

@ -1,43 +0,0 @@
// import('.Card');
class Card5 extends Card {
constructor(color, number, shape, filling, outline){
super();
if(color==''){
throw new EmptyParamaterException('Color');
}
if(number==''){
throw new EmptyParamaterException('Number');
}
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(filling==''){
throw new EmptyParamaterException('Filling');
}
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.color=color;
this.number=number;
this.shape=shape;
this.filling=filling;
this.outline=outline;
}
/**
* @returns array of all attributes :
idx 1 : color
idx 2 : number
idx 3 : shape
idx 4 : filling
idx 5 : outline
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling,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};
Loading…
Cancel
Save