edit to make possible the choice of the attributes

pull/32/head
Bastien JACQUELIN 2 years ago
parent 0273994afb
commit 2b6dcc5666

@ -17,6 +17,7 @@
<script src="../Model/unfoundCardException.js"></script> <script src="../Model/unfoundCardException.js"></script>
<script src="../Model/Card.js"></script> <script src="../Model/Card.js"></script>
<script src="../Model/Card5.js"></script> <script src="../Model/Card5.js"></script>
<script src="../Model/Const.js"></script>
<script src="../Model/Deck.js"></script> <script src="../Model/Deck.js"></script>
<script src="main.js"></script> <script src="main.js"></script>
</body> </body>

@ -27,11 +27,11 @@ try {
} }
console.groupEnd(); console.groupEnd();
console.group('Deck'); console.group('Deck');
let deck = new Deck(4); let deck = new Deck([0,1,2,3],4);
console.log(`All cards with 4 attributes size ${deck.allCards.length}`); console.log(`All cards with 4 attributes size ${deck.allCards.length}`);
console.log(`size ${deck.outputCards.length}`); console.log(`size output ${deck.outputCards.length}`);
// Display all cards
// 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);
// }); // });
@ -41,30 +41,22 @@ deck.outputCards.forEach(e => {
}); });
console.log(`set already made ${deck.setMade}`); 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')]; let customCard=[new Card('red',1,'diamond','stripped')];
deck.checkSet(customCard); //deck.checkSet(customCard);
console.log(`deck size :${deck.allCards.length}`); 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:`); console.log(`remaining cars:`);
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 deck5 = new Deck(5) //let deck5 = new Deck([0,1,2,3,4]);
console.log(`All cards with 5 attributes size ${deck5.allCards.length}`); //console.log(`All cards with 5 attributes size ${deck5.allCards.length}`);
// deck5.allCards.forEach(e => { // deck5.allCards.forEach(e => {
// console.log(e.color,e.number,e.shape,e.filling,e.outline); // console.log(e.color,e.number,e.shape,e.filling,e.outline);
// }); // });
//console.log(`Remaining cards ${deck.remainingCards}`); //console.log(`Remaining cards ${deck.remainingCards}`);
//console.log(`random : ${deck.getRandCard()}`); //console.log(`random : ${deck.getRandCard()}`);
console.groupEnd(); console.groupEnd();

@ -1,21 +1,25 @@
class Card{ class Card{
constructor(color, number, shape, filling){ constructor(color, number, shape, filling, outline){
if(!color){ if(color=''){
throw new EmptyParamaterException('Color'); throw new EmptyParamaterException('Color');
} }
if(!number){ if(number=''){
throw new EmptyParamaterException('Number'); throw new EmptyParamaterException('Number');
} }
if(!shape){ if(shape==''){
throw new EmptyParamaterException('Shape'); throw new EmptyParamaterException('Shape');
} }
if(!filling){ if(filling==''){
throw new EmptyParamaterException('Filling'); throw new EmptyParamaterException('Filling');
} }
if(outline==''){
throw new EmptyParamaterException('Outline');
}
this.color=color; this.color=color;
this.number=number; this.number=number;
this.shape=shape; this.shape=shape;
this.filling=filling; this.filling=filling;
this.outline=outline;
} }
/** /**
* @returns array of all attributes : * @returns array of all attributes :
@ -27,10 +31,10 @@ class Card{
* @author Bastien Jacquelin * @author Bastien Jacquelin
*/ */
getAttributes(){ getAttributes(){
return [this.color,this.number,this.shape,this.filling]; return [this.color,this.number,this.shape,this.filling,this.outline];
} }
equals(card){ equals(card){
return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling; return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ;
} }
}//export {Card} }//export {Card}

@ -0,0 +1,6 @@
const tabColor = ['red','purple','green','blue','orange'];
const tabNumber = [1,2,3,4,5];
const tabShape = ['diamond','oval','wave','star','triangle'];
const tabFilling = ['empty','stripped','full','pointed','squared'];
const tabOutline = ['full','dotted ','hyphen','cloudy','sharpy'];
const ATTRIBUTES=[tabColor,tabNumber,tabShape,tabFilling,tabOutline]

@ -1,11 +1,40 @@
class Deck{ class Deck{
constructor(nbAttributes=4){ /**
this.allCards=this.createCards(nbAttributes);// All the cards in the game *
* @param {*} attributes : array with the attributes index for the cards
*/
constructor(attributes,nbAttributes){
let attributesRequired=this.attributesRequiredFun(attributes);
attributesRequired.forEach(e=>{
for(let i=0;i<e.length;i++){
console.log(e[i]);
}
console.log(`lenght: ${e.length}`);
console.log('------');
});
this.allCards=this.createCards(attributesRequired,nbAttributes);// All the cards in the game
this.remainingCards=this.allCards;// cards in the stack this.remainingCards=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();
} }
attributesRequiredFun(attributes){
let attributesRequiredTmp=[];
let nullArray=[0,0,0,0,0];
for(let i=0;i<5;i++){
let find=false;
for (let j=0;j<attributes.length;j++){
if(i==attributes[j]){
attributesRequiredTmp.push(ATTRIBUTES[j]);
find=true;
}
}
if(!find){
attributesRequiredTmp.push(nullArray);
}
}
return attributesRequiredTmp;
}
createDeck(){ createDeck(){
for (let i=0; i<12; i++){ for (let i=0; i<12; i++){
const rand = this.getRandCard(); const rand = this.getRandCard();
@ -19,27 +48,18 @@ class Deck{
} }
/** /**
* *
* @param {*} nbAttributes : attributes of the card, by default = 4 * @param nbAttributes : attributes of the card, by default = 4
* @returns all cards: 81 in case of 4 attributes and 1224 * @returns all cards: 81 in case of 4 attributes and 1224
*/ */
createCards(nbAttributes){ createCards(attributes,nbAttributes){
const tabColor = ['red','purple','green','blue','orange'];
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=[]; let tabOfAllCards=[];
for (let c=0; c<nbAttributes-1; c++){
for (let n=0; n<nbAttributes-1; n++){ for (let c=0; c<this.lower(attributes[0].length,nbAttributes)-1; c++){
for (let s=0; s<nbAttributes-1; s++){ for (let n=0; n<this.lower(attributes[1].length,nbAttributes)-1; n++){
for (let f=0; f<nbAttributes-1; f++){ for (let s=0; s<this.lower(attributes[2].length,nbAttributes)-1; s++){
if(nbAttributes==4){ for (let f=0; f<this.lower(attributes[3].length,nbAttributes)-1; f++){
tabOfAllCards.push(new Card(tabColor[c],tabNumber[n],tabShape[s],tabFilling[f])); for (let o=0; o<this.lower(attributes[4].length,nbAttributes)-1; o++){
} tabOfAllCards.push(new Card(attributes[0][c],attributes[1][n],attributes[2][s],attributes[3][f],attributes[4][o]));
else{
for(let o=0;o<nbAttributes-1;o++){
tabOfAllCards.push(new Card5(tabColor[c],tabNumber[n],tabShape[s],tabFilling[f],tabOutline[o]));
}
} }
} }
} }
@ -47,6 +67,9 @@ class Deck{
} }
return tabOfAllCards; return tabOfAllCards;
} }
lower(length,nbAttributes){
return nbAttributes<length?nbAttributes:length;
}
checkSet(selectedCards){ checkSet(selectedCards){
if(true){//isSet(selectedCards)){ if(true){//isSet(selectedCards)){
selectedCards.forEach(e => { selectedCards.forEach(e => {

Loading…
Cancel
Save