Guest User

Untitled

a guest
May 22nd, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.87 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2.  
  3. <html>
  4. <head>
  5. <script>
  6. window.onload = function(){
  7. var canvas = document.getElementById("myCanvas");
  8. var context = canvas.getContext("2d");
  9.  
  10. var my=0;
  11. var CorrectAnswer=0;
  12. var qnumber=0;
  13. var rightanswers=0;
  14. var wronganswers=0;
  15. var QuizFinished=false;
  16. var lock=false;
  17. var textpos1=100;
  18. var textpos2=263;
  19. var textpos3=350;
  20. var textpos4=430;
  21. var Questions=["Osoba zaslužna za nastanak rokokoa je:?", "Kako se zvala silueta koja je nastupila nakon baroka?","Koji se poznati filmski lik smatra modnom ikonom, a nosila je krinoline?"];
  22.  
  23. var quizbg = new Image();
  24. quizbg.onload=function(){
  25. context.drawImage(quizbg,0,20);
  26. SetQuestions();
  27. }
  28. quizbg.src="untitled.png";
  29.  
  30. function SetQuestions(){
  31. if (qnumber==0){
  32. context.fillStyle="black";
  33. context.textBaseline="middle";
  34. context.font="30px Century Gothic";
  35.  
  36. context.fillText(Questions[qnumber],140,textpos1);
  37. context.font="25px Century Gothic";
  38. context.fillStyle="black";
  39. context.fillText("Madame de Pomadour",390,textpos2);//točan
  40. context.fillText("Marija Antoaneta",390,textpos3);
  41. context.fillText("Carica Sisi",390,textpos4);
  42. }
  43.  
  44. if (qnumber==1){
  45. context.fillStyle="black";
  46. context.textBaseline="middle";
  47. context.font="25px Century Gothic";
  48.  
  49. context.fillText(Questions[qnumber],140,textpos1);
  50. context.font="25px Century Gothic";
  51. context.fillStyle="black";
  52. context.fillText("'Svečana silueta'",390,textpos2);
  53. context.fillText("Raskošna silueta",390,textpos3);
  54. context.fillText("Empirijska silueta",390,textpos4);//točan
  55. }
  56.  
  57. if (qnumber==2){
  58. context.fillStyle="black";
  59. context.textBaseline="middle";
  60. context.font="20px Century Gothic";
  61.  
  62. context.fillText(Questions[qnumber],140,textpos1);
  63. context.font="25px Century Gothic";
  64. context.fillStyle="black";
  65. context.fillText("Regina George",390,textpos2);
  66. context.fillText("Scarlett O'Hara",390,textpos3);//točan
  67. context.fillText("Cher Horowitz",390,textpos4);
  68. }
  69. }
  70. canvas.addEventListener('click',ProcessClick);
  71.  
  72. function ProcessClick(event){
  73.  
  74. my=event.pageY - canvas.offsetTop;
  75. if(lock){
  76. ResetQ();
  77. }
  78. else{
  79. //prvo pitanje
  80. if((my>263 && my<290) &&(qnumber==0)){
  81. context.drawImage(quizbg, 25,625,150,50,840,225,150,50);
  82. rightanswers++;
  83. context.font="20px Century Gothic";
  84. context.fillText("Klikni za nastavak",30,570);
  85. lock=true;
  86. }
  87. if((my>350 && my<389) &&(qnumber==0)){
  88. context.drawImage(quizbg,200,625,150,50,840,350,150,50);
  89. wronganswers++;
  90. context.font="20px Century Gothic";
  91. context.fillText("Klikni za nastavak",30,570);
  92. lock=true;
  93. }
  94. if((my>430 && my<480) &&(qnumber==0)){
  95. context.drawImage(quizbg,200,625,150,50,840,475,150,50);
  96. wronganswers++;
  97. context.font="20px Century Gothic";
  98. context.fillText("Klikni za nastavak",30,570);
  99. lock=true;
  100. }
  101.  
  102. //drugo pitanje
  103. if((my>263 && my<290) &&(qnumber==1)){
  104. context.drawImage(quizbg,200,625,150,50,840,225,150,50);
  105. wronganswers++;
  106. context.font="20px Century Gothic";
  107. context.fillText("Klikni za nastavak",30,570);
  108. lock=true;
  109. }
  110. if((my>350 && my<389) &&(qnumber==1)){
  111. context.drawImage(quizbg,200,625,150,50,840,350,150,50);
  112. wronganswers++;
  113. context.font="20px Century Gothic";
  114. context.fillText("Klikni za nastavak",30,570);
  115. lock=true;
  116. }
  117. if((my>430 && my<480) &&(qnumber==1)){
  118. context.drawImage(quizbg,25,625,150,50,840,475,150,50);
  119. rightanswers++;
  120. context.font="20px Century Gothic";
  121. context.fillText("Klikni za nastavak",30,570);
  122. lock=true;
  123. }
  124.  
  125. //trece pitanje
  126. if((my>263 && my<290) &&(qnumber==2)){
  127. context.drawImage(quizbg,200,625,150,50,840,225,150,50);
  128. wronganswers++;
  129. context.font="20px Century Gothic";
  130. context.fillText("Klikni za nastavak",30,570);
  131. lock=true;
  132. }
  133. if((my>350 && my<389) &&(qnumber==2)){
  134. context.drawImage(quizbg,25,625,150,50,840,350,150,50);
  135. rightanswers++;
  136. context.font="20px Century Gothic";
  137. context.fillText("Klikni za nastavak",30,570);
  138. lock=true;
  139. }
  140. if((my>430 && my<600) &&(qnumber==2)){
  141. context.drawImage(quizbg,200,625,150,50,840,475,150,50);
  142. wronganswers++;
  143. context.font="20px Century Gothic";
  144. context.fillText("Klikni za nastavak",30,570);
  145. lock=true;
  146. }
  147. }
  148. }
  149.  
  150. function ResetQ(){
  151. lock=false;
  152. context.clearRect(0,0,1000,1000);
  153. qnumber++;
  154. if(qnumber==Questions.length){EndQuiz();}
  155. else{
  156. context.drawImage(quizbg,0,20);
  157. SetQuestions();
  158. }
  159. }
  160.  
  161. function EndQuiz(){
  162. canvas.removeEventListener('click',ProcessClick);
  163. context.drawImage(quizbg, 75,40,850,130,0,0,0,100);
  164. context.fillStyle="black";
  165. context.font="40px Century Gothic";
  166. context.fillText("Kraj",20,200);
  167. context.font="25px Century Gothic";
  168. context.fillText("Broj točnih odgovora: "+ rightanswers,20,300);
  169. context.fillText("Broj netočnih odgovora: "+ wronganswers,20,350);
  170. }
  171.  
  172. };
  173.  
  174. </script>
  175. </head>
  176. <style>
  177. #myCanvas{
  178. background-image: url(PozadinaKviz.jpg);
  179. }
  180. </style>
  181. <body>
  182. <canvas id="myCanvas" width="1000" height="600" style="border: 1px solid black; position: absolute; left: 50px; top: 50px"></canvas>
  183. </body>
  184. </html>
Add Comment
Please, Sign In to add comment