From ecc4d5aca4e6013bfef8624a3a6babbd258e5701 Mon Sep 17 00:00:00 2001 From: bajacqueli Date: Tue, 21 Mar 2023 20:59:42 +0100 Subject: [PATCH] check if selected cards are equal to do a set call methods of deck tu actualize deck BUG : click twice on already clicked card --- views/deck-module.js | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/views/deck-module.js b/views/deck-module.js index 6ad78cd..8429563 100644 --- a/views/deck-module.js +++ b/views/deck-module.js @@ -5,16 +5,45 @@ export default{ card:new Card({"filling":"empty"}), deck : new Deck([0,1,2,3],3), id:0, - selectedCards:[] + selectedCards:[], + nbCardsSelected:0 } }, methods:{ selected(id){ - console.log("selected",id); - this.selectedCards[id]=this.deck.outputCards[id-1] + if(this.nbCardsSelected>=this.deck.nbCards){ + document.querySelector(`#id${id}`).setAttribute("style","border: 2px solid black; margin: 20px; color: red; fontSize: 20px; cursor: pointer"); + } + else{ + this.nbCardsSelected+=1; + console.log("this.nbCardsSelected",this.nbCardsSelected); + console.log("selected",id); + this.selectedCards[id]=this.deck.outputCards[id-1] + console.log('selectedCards add',this.selectedCards); + if(this.nbCardsSelected==this.deck.nbCards){ + this.set(); + console.log("dqsdgqhj") + } + } }, unSelected(id){ - console.log("unSelected",id); + if(this.selectedCards[id]!=null){ + this.selectedCards.splice(id,1); + this.nbCardsSelected-=1; + console.log("this.nbCardsSelected",this.nbCardsSelected); + console.log('selectedCards remove',this.selectedCards); + console.log("unSelected",id); + } + }, + set(){ + console.log("Check Set") + let checkSet=true; + if(checkSet){ + this.deck.checkSet(this.selectedCards); + this.nbCardsSelected=0; + this.selectedCards.splice(0,this.selectedCards.length+1) + console.log("this.selectedCards.length",this.selectedCards.length) + } }, }, template:`