|
|
|
@ -2,21 +2,24 @@ class Deck{
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {*} attributes : array with the attributes index for the cards
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
constructor(attributes){
|
|
|
|
|
constructor(attributes,nbCards){
|
|
|
|
|
//console.log(attributes);
|
|
|
|
|
this.allCards=this.createCards(attributes);// All the cards in the game
|
|
|
|
|
this.remainingCards=[]
|
|
|
|
|
this.nbCards=nbCards;
|
|
|
|
|
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();
|
|
|
|
|
this.createDeck(12);
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @brief creation of the deck : call factory to create the good cards
|
|
|
|
|
* @brief creation of the deck : 12 cards lay in front of the player
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
createDeck(){
|
|
|
|
|
for (let i=0; i<12; i++){
|
|
|
|
|
createDeck(nbCards){
|
|
|
|
|
for (let i=0; i<nbCards; i++){
|
|
|
|
|
const rand = this.getRandCard();
|
|
|
|
|
this.outputCards.push(this.remainingCards[rand]);
|
|
|
|
|
this.remainingCards.splice(rand,1);
|
|
|
|
@ -25,6 +28,7 @@ class Deck{
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @returns random number in range of the array size
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
getRandCard(){
|
|
|
|
|
const random = Math.floor(Math.random() * this.remainingCards.length);
|
|
|
|
@ -34,11 +38,17 @@ class Deck{
|
|
|
|
|
*
|
|
|
|
|
* @param attributes : index of the attributes used
|
|
|
|
|
* @returns all cards: 81 in case of 4 attributes and 1024 if 5 attributes
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
createCards(attributes){
|
|
|
|
|
let factory = new Factory(attributes)
|
|
|
|
|
return factory.product
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* @brief verification of the validity of the set selected
|
|
|
|
|
* @param {*} selectedCards array of cards : set
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
checkSet(selectedCards){
|
|
|
|
|
if(true){//isSet(selectedCards)){
|
|
|
|
|
selectedCards.forEach(e => {
|
|
|
|
@ -47,8 +57,9 @@ class Deck{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {*} selectedCards wehn a set is made, need to remove the card from the array remainingCards
|
|
|
|
|
* @brief when a set is made, need to remove the card from the array remainingCards
|
|
|
|
|
* @param {*} selectedCards cards which need to be removed from the outputcards
|
|
|
|
|
* @author Bastien Jacquelin
|
|
|
|
|
*/
|
|
|
|
|
removeFromoutputCards(selectedCards){//better check of card type more opti
|
|
|
|
|
let set=[];
|
|
|
|
@ -65,6 +76,7 @@ class Deck{
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
this.setMade.push(set);
|
|
|
|
|
this.createDeck(this.nbCards)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|