Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.11 KB | None | 0 0
  1. var x = false;
  2.  
  3.  
  4. class soundEffects
  5. {
  6. constructor()
  7. {
  8. this.backGroundMusic = new Audio('Sounds/BackGround.mp3');
  9. this.backGroundMusic.volume=0.5;
  10. this.backGroundMusic.loop= true;
  11. this.flipSoundvoice = new Audio('Sounds/flip.wav');
  12. this.introMusic = new Audio ('Sounds/Intro.mp3');
  13. this.matchedVoice = new Audio ('Sounds/Matched.mp3');
  14. this.victoRy= new Audio('Sounds/Victory.mp3');
  15. }
  16. flipSound()
  17. {
  18. this.flipSoundvoice.play();
  19. }
  20. intro()
  21. {
  22. this.introMusic.play();
  23. }
  24. back()
  25. {
  26. this.backGroundMusic.play();
  27. }
  28. matchedS()
  29. {
  30. this.matchedVoice.play();
  31. }
  32. victory()
  33. {
  34. this.victoRy.play();
  35. }
  36. }
  37. function startGame(nOofPairs){
  38.  
  39. var cards;
  40. alert(nOofPairs);
  41. if (nOofPairs === 36)
  42. {
  43. cards= document.querySelectorAll('.memory-card');
  44. cards.forEach(card => {
  45. card.classList.remove('flip');
  46. });
  47.  
  48. }
  49.  
  50. if (nOofPairs === '64')
  51. {
  52. var div = document.createElement('div');
  53. div.className = 'memory-card';
  54. div.innerHTML =
  55. '<img class="front-face" src="2.png" >\
  56. <img class="back-face" src="back.png">';
  57. document.getElementById('content').appendChild(div);
  58.  
  59. var div2 = document.createElement('div2');
  60. div2.className = 'memory-card';
  61. div2.innerHTML =
  62. '<img class="front-face" src="2.png" >\
  63. <img class="back-face" src="back.png">';
  64. document.getElementById('content').appendChild(div2);
  65.  
  66. cards= document.querySelectorAll('.memory-card');
  67. cards.forEach(card => {
  68. card.classList.remove('flip');
  69. });
  70.  
  71.  
  72. }
  73.  
  74.  
  75.  
  76. //let sound = new soundEffects();
  77. sound.intro();
  78. //sound.back();
  79. //const cards= document.querySelectorAll('.memory-card');
  80. /*cards.forEach(card => {
  81. card.classList.remove('flip');
  82. });
  83. */
  84.  
  85.  
  86. let hasFlippedCard=false;
  87. let firstCard, secondCard;
  88. let lockBoard=false;
  89. var flips=0;
  90. var counter=0;
  91. var hit=0;
  92.  
  93.  
  94. function flipCard(){
  95. if(lockBoard){return;}
  96. if(this===firstCard){return;}
  97.  
  98. flips++;
  99. sound.flipSound();
  100. document.getElementById('flips').innerText=flips;
  101. this.classList.toggle('flip');
  102.  
  103. if(!hasFlippedCard){
  104.  
  105. hasFlippedCard=true;
  106. firstCard=this;
  107. }
  108. else{
  109. hasFlippedCard=false;
  110. secondCard=this;
  111.  
  112. if(firstCard.dataset.framework===secondCard.dataset.framework){
  113. firstCard.removeEventListener('click',flipCard);
  114. secondCard.removeEventListener('click',flipCard);
  115. hit++;
  116. sound.matchedS();
  117. }
  118. else{
  119. lockBoard=true;
  120. setTimeout(() => {
  121. firstCard.classList.remove('flip');
  122. secondCard.classList.remove('flip');
  123. lockBoard=false;
  124. firstCard= null;
  125. },1500);
  126. }
  127. }
  128. }
  129. /*(function shuffle(){
  130. cards.forEach(card => {
  131. let randomPos = Math.floor(Math.random()*36);
  132. card.style.order = randomPos;
  133. });
  134. })();*/
  135. cards.forEach(card => card.addEventListener('click',flipCard));
  136.  
  137. function time(){
  138. document.getElementById('time-remaining').innerText=counter;
  139. counter++;
  140. if(hit==18){clearInterval(t);
  141. document.getElementById('victory-text').classList.add('visible');
  142. sound.victory();
  143. document.getElementById('flips').innerText=0;
  144. }
  145. }
  146.  
  147. var t=setInterval(time,1000);
  148.  
  149. }
  150.  
  151. let sound = new soundEffects();
  152.  
  153. function updateCards()
  154. {
  155. var e = document.getElementById("keke");
  156. let strUser = e.options[e.selectedIndex].value;
  157. startGame(strUser);
  158. }
  159.  
  160.  
  161. //startGame(strUser);
  162.  
  163.  
  164. let overlays = Array.from(document.getElementsByClassName('overlay-text'));
  165. overlays.forEach( overlay => {
  166. overlay.addEventListener('click',() => {
  167. overlay.classList.remove('visible');
  168. sound.back();
  169. startGame(36);
  170. });
  171. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement