$this.shuffle = function(arr){ arr.sort(() => random(1, -1)); return arr; }; if ($this.scene.state() == "PLAY") { $this.orderedCardlist = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8]; $this.randomCardList = $this.shuffle($this.orderedCardlist); var cardListIndex = 0; var cardSpacing = 100; var xOffset = 200; var yOffset = 70; for (var cx = 0; cx < 4; cx++){ for (var cy = 0; cy < 4; cy++){ var cardClone = card.clone(); cardClone.x(cx * cardSpacing + xOffset); cardClone.y(cy * cardSpacing + yOffset); cardClone.picture = $this.randomCardList[cardListIndex]; cardListIndex++; } } $this.firstCard = null $this.secondCard = null card.visible(false); } $this.ischeck = false; $this.checkMatch = function() { if ($this.firstCard.picture === $this.secondCard.picture){ $this.firstCard.remove(); $this.secondCard.remove(); }else{ $this.firstCard.frameIndex(0); $this.secondCard.frameIndex(0); } $this.firstCard = null; $this.secondCard = null; $this.ischecking= false };
if ($this.scene.is checking === false) { $this.frameIndex($this.picture); if (!$this.scene.firstCard) { $this.scene.firstCard = $this; } else if ($this != $this.scene.firstCard){ $this.scene.secondCard = $this; $this.scene.checkMatch(); $this.scene.ischecking = true; createTimer(1000, $this.scene.checkMatch, false); } }