Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.98 KB | None | 0 0
  1.  
  2. <!DOCTyPE html>
  3.  
  4. <html lang="et">
  5.  
  6. <head>
  7.  
  8. <meta charset="UTF-8">
  9.  
  10. <title>kirbumang</title>
  11.  
  12. <style>
  13.  
  14. img{
  15.  
  16. width: 150px;
  17.  
  18. height: 150px;
  19.  
  20. }
  21.  
  22. body{
  23.  
  24. line-height: 2px;
  25.  
  26. margin-top: 5px;
  27.  
  28. }
  29.  
  30. </style>
  31.  
  32. <script>
  33.  
  34. kirpx = 1;
  35.  
  36. kirpy = 1;
  37.  
  38. kirpHypeteLoendur = 0
  39.  
  40. vastanex = 4;
  41.  
  42. vastaney = 1;
  43.  
  44. vastaneTaimer=false;
  45.  
  46. m2ngk2ib = true;
  47.  
  48. function vastaneHyppa(){
  49.  
  50. if(vastanex===4 && vastaney===4){
  51.  
  52. //alla nurka pilt ma ei tea
  53.  
  54. document.getElementById("a"+vastanex+vastaney).src = "happy.jpg";
  55.  
  56. }else{
  57.  
  58. //ülejäänud pildid asendab taustaga
  59.  
  60. document.getElementById("a"+vastanex+vastaney).src = "taust.png";
  61.  
  62. }
  63.  
  64. if(Math.random()<0.5){
  65.  
  66. if(vastanex===1){
  67.  
  68. vastanex++;
  69.  
  70. }else if(vastanex===4){
  71.  
  72. vastanex--;
  73.  
  74. }else if(Math.random()<0.5){
  75.  
  76. vastanex++;
  77.  
  78. }else{
  79.  
  80. vastanex--;
  81.  
  82. }
  83.  
  84. }else{
  85.  
  86. if(vastaney===1){
  87.  
  88. vastaney++;
  89.  
  90. }else if(vastaney===4){
  91.  
  92. vastaney--;
  93.  
  94. }else if(Math.random()<0.5){
  95.  
  96. vastaney++;
  97.  
  98. }else{
  99.  
  100. vastaney--;
  101.  
  102. }
  103.  
  104. }
  105.  
  106. //uues kohas nähtavale vm
  107.  
  108. document.getElementById("a"+vastanex+vastaney).src = "vastane.png";
  109.  
  110. //Kui vastane hüppas mulle peal
  111.  
  112. if(kirpx====vastanex && kirpy====vastaney){
  113.  
  114. m2ngk2ib = false;
  115.  
  116. window.clearInterval(vastaneTaimer);
  117.  
  118. vastaneTaimer = false;
  119.  
  120. document.getElementById("a"+vastanex+vastaney).src = "suvetoo.png";
  121.  
  122. document.getElementById("info").innerHTML = "Sa lähed suvetööle!";
  123.  
  124. }
  125.  
  126. }
  127.  
  128. function hyppa(x, y){
  129.  
  130. if(kirpx===x && kirpy===y && m2ngk2ib){
  131.  
  132. if(!vastaneTaimer){
  133.  
  134. vastaneTaimer = window.setInterval(vastaneHyppa, 1000);
  135.  
  136. }
  137.  
  138. if(Math.random()<0.5){
  139.  
  140. if(kirpx===1){
  141.  
  142. kirpx++;
  143.  
  144. }else if(kirpx===4){
  145.  
  146. kirpx--;
  147.  
  148.  
  149. }else if(Math.random()<0.5){
  150.  
  151. kirpx++;
  152.  
  153. }else{
  154.  
  155. kirpx--;
  156.  
  157. }
  158.  
  159. }else{
  160.  
  161. if(kirpy===1){
  162.  
  163. kirpy++;
  164.  
  165. }else if(kirpy===4){
  166.  
  167. kirpy--;
  168.  
  169. }else if(Math.random()<0.5){
  170.  
  171. kirpy++;
  172.  
  173. }else{
  174.  
  175. kirpy--;
  176.  
  177. }
  178.  
  179. }
  180.  
  181. kirpHypeteLoendur++;
  182.  
  183. document.getElementById("a"+x+y).src = "taust.png";
  184.  
  185. //Asendame kirbu uue asukoha
  186.  
  187. document.getElementById("a"+vastanex+vastaney).src = "kirp.png";
  188.  
  189. document.getElementById("info").innerHTML = "kirp on hüppanud " + hypped + " korda";
  190.  
  191. if(kirpx===vastanex && kirpy===vastaney){
  192.  
  193. window.clearInterval(vastaneTaimer);
  194.  
  195. vastaneTaimer = false;
  196.  
  197. document.getElementById("a"+vastanex+vastaney).src = "taust.png";
  198.  
  199. vastanex = 4;
  200.  
  201. vastaney = 1;
  202.  
  203. document.getElementById("a"+vastanex+vastaney).src = "vastane.png";
  204.  
  205. //siin oli mingi alternatiiv vist
  206.  
  207. if(kirpx====4 && kirpy====1){
  208.  
  209. kirpx = 1;
  210.  
  211. }
  212.  
  213. document.getElementById("a"+kirpx+kirpy).src = "kirp.jpg";
  214.  
  215. }
  216.  
  217. if(kirpx===4 && kirpy===4){
  218.  
  219. m2ngk2ib = false;
  220.  
  221. window.clearInterval(vastaneTaimer);
  222.  
  223. vastaneTaimer = false;
  224.  
  225. document.getElementById("a"+kirpx+kirpy).src = "happy.jpg";
  226.  
  227. document.getElementById("info").innerHTML = "Jõudsid suveni" + kirbuHypeteLoendur + " hüppega";
  228.  
  229. }
  230.  
  231. }
  232.  
  233. }
  234.  
  235. </script>
  236.  
  237. </head>
  238.  
  239. <body>
  240.  
  241. <img src="kirp.png" id="a11" onclick="hyppa(1,1)"><img src="taust.png" id="a21" onclick="hyppa(2,1)"><img src="taust.png" id="a31" onclick="hyppa(3,1)"><img src="vastane.png" id="a41" onclick="hyppa(4,1)"><br>
  242.  
  243. <img src="taust.png" id="a12" onclick="hyppa(1,2)"><img src="taust.png" id="a22" onclick="hyppa(2,2)"><img src="taust.png" id="a32" onclick="hyppa(3,2)"><img src="taust.png" id="a42" onclick="hyppa(4,2)"><br>
  244.  
  245. <img src="taust.png" id="a13" onclick="hyppa(1,3)"><img src="taust.png" id="a23" onclick="hyppa(2,3)"><img src="taust.png" id="a33" onclick="hyppa(3,3)"><img src="taust.png" id="a43" onclick="hyppa(4,3)"><br>
  246.  
  247. <img src="taust.png" id="a14" onclick="hyppa(1,4)"><img src="taust.png" id="a24" onclick="hyppa(2,4)"><img src="taust.png" id="a34" onclick="hyppa(3,4)"><img src="suvi.png" id="a44" onclick="hyppa(4,4)"><br>>
  248.  
  249. <h1 id="info">Päästa mind suvetööst!</h1>
  250.  
  251. </body>
  252.  
  253. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement