parent
29e8e23c90
commit
99ed8b1233
@ -1,40 +1,15 @@
|
|||||||
class Card{
|
class Card{
|
||||||
constructor(color, number, shape, filling, outline){
|
constructor(){}
|
||||||
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
|
* @returns all attributes of a card
|
||||||
idx 2 : number
|
|
||||||
idx 3 : shape
|
|
||||||
idx 4 : filling
|
|
||||||
idx 5 : null
|
|
||||||
* @author Bastien Jacquelin
|
|
||||||
*/
|
*/
|
||||||
getAttributes(){
|
getAttributes(){}
|
||||||
return [this.color,this.number,this.shape,this.filling,this.outline];
|
/**
|
||||||
}
|
*
|
||||||
equals(card){
|
* @param {*} card card to be compared with the current obj
|
||||||
return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ;
|
* @returns boolean
|
||||||
}
|
*/
|
||||||
|
equals(card){}
|
||||||
|
|
||||||
}//export {Card}
|
}//export {Card}
|
@ -0,0 +1,27 @@
|
|||||||
|
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 ;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
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 ;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
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 ;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
class Card4WithoutOutline extends Card{
|
||||||
|
constructor(color, number, shape, filling){
|
||||||
|
super();
|
||||||
|
if(number==''){
|
||||||
|
throw new EmptyParamaterException('Number');
|
||||||
|
}
|
||||||
|
if(shape==''){
|
||||||
|
throw new EmptyParamaterException('Shape');
|
||||||
|
}
|
||||||
|
if(filling==''){
|
||||||
|
throw new EmptyParamaterException('Filling');
|
||||||
|
}
|
||||||
|
if(color==''){
|
||||||
|
throw new EmptyParamaterException('Color');
|
||||||
|
}
|
||||||
|
this.number=number;
|
||||||
|
this.shape=shape;
|
||||||
|
this.filling=filling;
|
||||||
|
this.color=color;
|
||||||
|
}
|
||||||
|
getAttributes(){
|
||||||
|
return [this.number,this.shape,this.filling,this.color];
|
||||||
|
}
|
||||||
|
equals(card){
|
||||||
|
return this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.color===card.color;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
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 ;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,82 @@
|
|||||||
|
class Factory{
|
||||||
|
constructor(arrayOfAttributes){
|
||||||
|
let length=arrayOfAttributes.length
|
||||||
|
this.product=this.concreteCardCreation(arrayOfAttributes,length);
|
||||||
|
}
|
||||||
|
attributesRequiredFun(arrayOfAttributes,length){
|
||||||
|
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){
|
||||||
|
attributesRequiredTmp.push(nullArray);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return attributesRequiredTmp;
|
||||||
|
}
|
||||||
|
concreteCardCreation(arrayOfAttributes, length){
|
||||||
|
let tabOfAllCards=[];
|
||||||
|
let attributes=this.attributesRequiredFun(arrayOfAttributes,length);
|
||||||
|
let nbAttributes=length
|
||||||
|
if(nbAttributes==3){
|
||||||
|
for (let c=0; c<nbAttributes-1; c++){
|
||||||
|
for (let n=0; n<nbAttributes-1; n++){
|
||||||
|
for (let s=0; s<nbAttributes-1; s++){
|
||||||
|
tabOfAllCards.push(new Card3(ATTRIBUTES[0][c],ATTRIBUTES[1][n],ATTRIBUTES[2][s]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(nbAttributes==4){
|
||||||
|
for (let n=0; n<nbAttributes-1; n++){
|
||||||
|
for (let s=0; s<nbAttributes-1; s++){
|
||||||
|
for (let f=0; f<nbAttributes-1; f++){
|
||||||
|
for (let o=0; o<nbAttributes-1; o++){
|
||||||
|
if(attributes[0][0]===0){
|
||||||
|
tabOfAllCards.push(new Card4WithoutColor(attributes[1][n],attributes[2][s],attributes[3][f],attributes[4][o]));
|
||||||
|
}
|
||||||
|
else if(attributes[1][0]===0){
|
||||||
|
tabOfAllCards.push(new Card4WithoutNumber(attributes[0][n],attributes[2][s],attributes[3][f],attributes[4][o]));
|
||||||
|
}
|
||||||
|
else if(attributes[2][0]===0){
|
||||||
|
tabOfAllCards.push(new Card4WithoutShape(attributes[0][n],attributes[1][s],attributes[3][f],attributes[4][o]));
|
||||||
|
}
|
||||||
|
else if(attributes[3][0]===0){
|
||||||
|
console.log(attributes[0][n],attributes[1][s],attributes[2][f],attributes[4][o]);
|
||||||
|
tabOfAllCards.push(new Card4WithoutFilling(attributes[0][n],attributes[1][s],attributes[2][f],attributes[4][o]));
|
||||||
|
}
|
||||||
|
else if(attributes[4][0]===0){
|
||||||
|
console.log('rentre la');
|
||||||
|
console.log(attributes[0][n],attributes[1][s],attributes[2][f],attributes[3][o]);
|
||||||
|
tabOfAllCards.push(new Card4WithoutOutline(attributes[0][n],attributes[1][s],attributes[2][f],attributes[3][o]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if(nbAttributes==5){
|
||||||
|
for (let c=0; c<nbAttributes-1; c++){
|
||||||
|
for (let n=0; n<nbAttributes-1; n++){
|
||||||
|
for (let s=0; s<nbAttributes-1; s++){
|
||||||
|
for (let f=0; f<nbAttributes-1; f++){
|
||||||
|
for (let o=0; o<nbAttributes-1; o++){
|
||||||
|
tabOfAllCards.push(new Card5(attributes[0][c],attributes[1][n],attributes[2][s],attributes[3][f],attributes[4][o]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
//ERROR
|
||||||
|
}
|
||||||
|
return tabOfAllCards
|
||||||
|
}
|
||||||
|
}
|
@ -1,20 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
|
|
||||||
<html lang="en">
|
|
||||||
|
|
||||||
<head>
|
|
||||||
<title>My awesome blog</title>
|
|
||||||
</head>
|
|
||||||
|
|
||||||
<body>
|
|
||||||
<h1>My awesome blog</h1>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
<script src="./Model/Card.js"></script>
|
|
||||||
<script src="./algo.js"></script>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
main();
|
|
||||||
</script>
|
|
||||||
|
|
||||||
</html>
|
|
Loading…
Reference in new issue