index.html 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel="stylesheet" href="style.css">
  9. <script src="index.js"></script>
  10. <script>
  11. </script>
  12. </head>
  13. <body>
  14. <div class="header">Score:<span id="score">0</span></div>
  15. <div id="buttonStart"><img src="round_button.png">Гасить русню!</div>
  16. <div class="playing_field" id = "playingField">
  17. <div class="rectangle">
  18. <div class="beaverHome">
  19. <div class="beaver" id="beaver1"></div>
  20. </div>
  21. </div>
  22. <div class="rectangle">
  23. <div class="beaverHome" >
  24. <div class="beaver" id="beaver2"></div>
  25. </div>
  26. </div>
  27. <div class="rectangle">
  28. <div class="beaverHome">
  29. <div class="beaver" id="beaver3"></div>
  30. </div>
  31. </div>
  32. <div class="rectangle">
  33. <div class="beaverHome">
  34. <div class="beaver" id="beaver4"></div>
  35. </div>
  36. </div>
  37. <div class="rectangle">
  38. <div class="beaverHome">
  39. <div class="beaver" id="beaver5"></div>
  40. </div>
  41. </div>
  42. </div>
  43. <div class="cursor"></div>
  44. </body>
  45. <script>
  46. let scoreValue = 0
  47. let TimeVision = 3000
  48. const cursor = document.querySelector('.cursor')
  49. beaver1.onclick = () => {
  50. beaver1.style.pointerEvents = "none"
  51. scoreValue += 10;
  52. score.innerText = scoreValue;
  53. beaver1.style.backgroundColor = "red"
  54. beaver1.style.transform = 'translate(-50% , -50%) rotateX(90deg)'
  55. cry()
  56. }
  57. beaver2.onclick = () => {
  58. beaver2.style.pointerEvents = "none"
  59. scoreValue += 10;
  60. score.innerText = scoreValue
  61. beaver2.style.backgroundColor = "red"
  62. beaver2.style.transform = 'translate(-50% , -50%) rotateX(90deg)'
  63. cry()
  64. }
  65. beaver3.onclick = () => {
  66. beaver3.style.pointerEvents = "none"
  67. scoreValue += 10;
  68. score.innerText = scoreValue
  69. beaver3.style.backgroundColor = "red"
  70. beaver3.style.transform = 'translate(-50% , -50%) rotateX(90deg)'
  71. cry()
  72. }
  73. beaver4.onclick = () => {
  74. beaver4.style.pointerEvents = "none"
  75. scoreValue += 10;
  76. score.innerText = scoreValue
  77. beaver4.style.backgroundColor = "red"
  78. beaver4.style.transform = 'translate(-50% , -50%) rotateX(90deg)'
  79. cry()
  80. }
  81. beaver5.addEventListener('click', () => {
  82. beaver5.style.pointerEvents = "none"
  83. scoreValue += 10;
  84. score.innerText = scoreValue
  85. beaver5.style.backgroundColor = "red"
  86. beaver5.style.transform = 'translate(-50% , -50%) rotateX(90deg)'
  87. cry()
  88. })
  89. const playAudio = () =>{
  90. let myAudio = new Audio;
  91. myAudio.src = "bam.mp3";
  92. myAudio.play();
  93. cursor.style.transition = ".05s"
  94. cursor.style.width = "150px"
  95. cursor.style.height = "150px"
  96. setTimeout(() => {
  97. cursor.style.transition = ""
  98. cursor.style.width = "100px"
  99. cursor.style.height = "100px"
  100. },200)
  101. }
  102. const cry = () =>{
  103. let audioCry = new Audio;
  104. audioCry.src = "mujskoy-krik-korotkiy.mp3";
  105. audioCry.play();
  106. }
  107. window.addEventListener('click', playAudio)
  108. let beaverDefaultFunction = () => {
  109. const arrbeaver = document.querySelectorAll('.beaver')
  110. for (let elemBeaver of arrbeaver) {
  111. elemBeaver.style.backgroundColor = "";
  112. elemBeaver.style.top = "-50%";
  113. elemBeaver.style.pointerEvents = "auto"
  114. elemBeaver.style.transform = "translate(-50% , -50%)"
  115. }
  116. }
  117. let beaverUpFunction = () => {
  118. if (TimeVision > 2000) {
  119. if (Math.random() > 0.5) beaver1.style.top = "50%"
  120. if (Math.random() > 0.5) beaver2.style.top = "50%"
  121. if (Math.random() > 0.5) beaver3.style.top = "50%"
  122. if (Math.random() > 0.5) beaver4.style.top = "50%"
  123. if (Math.random() > 0.5) beaver5.style.top = "50%"
  124. setTimeout(beaverDefaultFunction,TimeVision)
  125. TimeVision += -200;
  126. } else {
  127. clearInterval(interval)
  128. playingField.style.visibility = 'hidden'
  129. setTimeout( () => {
  130. buttonStart.style.display = 'flex'
  131. TimeVision = 3000
  132. }, 500)
  133. setTimeout( () => {
  134. buttonStart.style.opacity = '1'
  135. buttonStart.style.boxShadow = '0 4px 22px rgba(0,0,0, 0.25), inset 0 3px 0 rgba(255,255,255, 0.2), 0 3px 0 rgba(0,0,0, 0.1), inset 0 0 22px rgba(0,0,0, 0.1)'
  136. }, 500)
  137. }
  138. }
  139. let interval
  140. window.addEventListener('mousemove', e => {
  141. cursor.style.top = e.pageY + 'px'
  142. cursor.style.left = e.pageX + 'px'
  143. })
  144. buttonStart.addEventListener('click', () => {
  145. buttonStart.style.boxShadow = 'inset 0 0 22px rgba(0,0,0,0.2), 0 3px 0 rgba(255,255,255,0.4),inset 0 3px 0 rgba(0,0,0,0.1), inset 0 0 22px rgba(0,0,0,0.1)'
  146. setTimeout( () => {
  147. buttonStart.style.opacity = '0'
  148. playingField.style.visibility = 'visible'
  149. }, 500)
  150. setTimeout( () => {
  151. buttonStart.style.display = 'none'
  152. }, 500)
  153. setTimeout( () => 0 , 500)
  154. interval = setInterval(beaverUpFunction, 5000)
  155. })
  156. </script>
  157. </html>