Nerviie

JavaScript EXPOCIC

Mar 26th, 2019
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var vetor=new Array(30);
  2. for(i=0;i<30;i++){
  3.     vetor[i]=0;
  4. }
  5. var start=0;
  6. var jogadas=0;
  7. var cora=0;
  8. var wins=0;
  9. var lose=0;
  10. var bomba=0;
  11. var conta;
  12. var contax=0;
  13. var FM=0;
  14. function sorteio(t,q){
  15.     for(i=1;i<=parseInt(q);i++){
  16.         do{
  17.             u=Math.floor((Math.random() * 29) + 1);
  18.         }while(vetor[u]!=0);
  19.         vetor[u]=parseInt(t);
  20.     }
  21. }
  22. function depois(){
  23.     for(i=0;i<30;i++){
  24.         document.getElementById('t' + i).innerHTML='&nbsp;';
  25.         document.getElementById('t' + i).className="";
  26.         vetor[i]=0;
  27.     }
  28.     document.getElementById('w1').innerHTML=0;
  29.     document.getElementById('w2').innerHTML=0;
  30.     document.getElementById('w3').innerHTML=0;
  31. }
  32.  
  33. function clica(){
  34.     depois();
  35.     start=1;
  36.     sorteio(1,5);
  37.     sorteio(2,1);
  38.     sorteio(3,6);
  39.     document.getElementById('tabela').style="background-color: #4dc3ff;";
  40.     document.getElementById('butao').disabled="disabled";
  41. }
  42. function ok(){
  43.     document.getElementById('butao').disabled="";
  44.     bomba=0;
  45.     contax=0;
  46.     FM=0;
  47.     document.getElementById('w1').innerHTML=0;
  48.     document.getElementById('w2').innerHTML=0;
  49.     document.getElementById('w3').innerHTML=0;
  50.     clearTimeout(conta);
  51. }
  52. function cronometro(){
  53.     if(contax>=2){
  54.         clearTimeout(conta);
  55.         alert("Perdeu,Encontrou duas Bombas Temporizadas");
  56.         ok();
  57.         start=0;
  58.     }
  59. }
  60. function fim(){
  61.     document.getElementById('fm1').style.visibility = "hidden";
  62.     document.getElementById('fg').style.visibility = "visible";
  63.     document.getElementById('crl').style.visibility = "hidden";
  64.     document.getElementById('crl').style.display = "none";
  65.     document.getElementById('cli').style.visibility = "visible";
  66.     ok();
  67.     clearTimeout(conta);
  68. }
  69. function acabou(){
  70.     if(bomba==1){
  71.         alert("Ups, Escolheu um bomba!");
  72.         ok();
  73.         start=0
  74.         document.getElementById('o2').innerHTML=parseInt(document.getElementById('o2').innerHTML)+1;
  75.     }
  76.     else{
  77.         if(FM==6 && contax!=5){
  78.             clearTimeout(conta);
  79.             alert("Ganhou");
  80.             fim();
  81.             start=0;
  82.             document.getElementById('o1').innerHTML=parseInt(document.getElementById('o1').innerHTML)+1;
  83.         }
  84.     }
  85. }
  86.  
  87. function rt(x){
  88.     if(start==1){
  89.         if(document.getElementById('t' + x).innerHTML=='&nbsp;'){
  90.             jogadas++;
  91.             console.log(jogadas);
  92.             document.getElementById('cli').value++;
  93.             document.getElementById('t' + x).className="escolha";
  94.             switch (vetor[x]) {
  95.                     //--------------------Temporizador--------
  96.                 case 1: document.getElementById('t' + x).innerHTML='&#x23F1;';
  97.                     conta=setTimeout(function(){ alert("Perdeu, Não Encontrou o Bombeiro"); clearTimeout(conta); ok();}, 3000);
  98.                     contax++;
  99.                     document.getElementById('w2').innerHTML=parseInt(document.getElementById('w2').innerHTML)+1;
  100.                     cronometro();
  101.                     break;
  102.                     //--------------------Bomba--------------
  103.                 case 2: document.getElementById('t' + x).innerHTML='&#128163;';  
  104.                     document.getElementById('w1').innerHTML=parseInt(document.getElementById('w1').innerHTML)+1;
  105.                     bomba++;
  106.                     clearTimeout(conta);
  107.                     acabou();
  108.                     break;
  109.                     //--------------------Bombeiro-----------
  110.                 case 3: document.getElementById('t' + x).innerHTML='&#x1F468;&#x200D;&#x1F692;';
  111.                     document.getElementById('w3').innerHTML=parseInt(document.getElementById('w3').innerHTML)+1;
  112.                     FM++;
  113.                     if(contax>=1){
  114.                         contax=contax-1;
  115.                         clearTimeout(conta);
  116.                     }
  117.                     acabou();                  
  118.                     break;
  119.             }
  120.            
  121.         }
  122.     }
  123.     else
  124.         if(start==0){
  125.             alert("Tem de começar o jogo!");
  126.         }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment