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/Card.js"></script>
<script src="../Model/Card5.js"></script>
<script src="../Model/Const.js"></script>
<script src="../Model/Deck.js"></script>
<script src="main.js"></script>
</body>

@ -27,11 +27,11 @@ try {
}
console.groupEnd();
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(`size ${deck.outputCards.length}`);
console.log(`size output ${deck.outputCards.length}`);
// Display all cards
// deck.allCards.forEach(e => {
// 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}`);
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);
//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}`);
//let deck5 = new Deck([0,1,2,3,4]);
//console.log(`All cards with 5 attributes size ${deck5.allCards.length}`);
// deck5.allCards.forEach(e => {
// console.log(e.color,e.number,e.shape,e.filling,e.outline);
// });
//console.log(`Remaining cards ${deck.remainingCards}`);
//console.log(`random : ${deck.getRandCard()}`);
console.groupEnd();

@ -1,21 +1,25 @@
class Card{
constructor(color, number, shape, filling){
if(!color){
constructor(color, number, shape, filling, outline){
if(color=''){
throw new EmptyParamaterException('Color');
}
if(!number){
if(number=''){
throw new EmptyParamaterException('Number');
}
if(!shape){
if(shape==''){
throw new EmptyParamaterException('Shape');
}
if(!filling){
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 :
@ -27,10 +31,10 @@ class Card{
* @author Bastien Jacquelin
*/
getAttributes(){
return [this.color,this.number,this.shape,this.filling];
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;
return this.color===card.color && this.number===card.number && this.shape===card.shape && this.filling===card.filling && this.outline===card.outline ;
}
}//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{
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.outputCards=[];// 12 cards lay on the table
this.setMade=[];// array with all the set already mades (array of set)
//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(){
for (let i=0; i<12; i++){
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
*/
createCards(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'];
createCards(attributes,nbAttributes){
let tabOfAllCards=[];
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++){
if(nbAttributes==4){
tabOfAllCards.push(new Card(tabColor[c],tabNumber[n],tabShape[s],tabFilling[f]));
}
else{
for(let o=0;o<nbAttributes-1;o++){
tabOfAllCards.push(new Card5(tabColor[c],tabNumber[n],tabShape[s],tabFilling[f],tabOutline[o]));
}
for (let c=0; c<this.lower(attributes[0].length,nbAttributes)-1; c++){
for (let n=0; n<this.lower(attributes[1].length,nbAttributes)-1; n++){
for (let s=0; s<this.lower(attributes[2].length,nbAttributes)-1; s++){
for (let f=0; f<this.lower(attributes[3].length,nbAttributes)-1; 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]));
}
}
}
@ -47,6 +67,9 @@ class Deck{
}
return tabOfAllCards;
}
lower(length,nbAttributes){
return nbAttributes<length?nbAttributes:length;
}
checkSet(selectedCards){
if(true){//isSet(selectedCards)){
selectedCards.forEach(e => {

Loading…
Cancel
Save