Guest User

java

a guest
Jan 12th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.     var a= new Array();
  3.     var nr_pergunta=0;
  4.     /* var a= new Array();
  5.      var geografia_facil= "https://opentdb.com/api.php?amount=10&category=22&difficulty=easy&type=multiple";
  6.      var facil_geografia=JSON.stringify(a);
  7.      var jogo= $("#iniciar");
  8.  
  9.      $.getJSON(geografia_facil, function (data) {
  10.          a = data.results;
  11.          localStorage.setItem("sotrage",facil_geografia) ;
  12.  
  13.      });
  14.      */
  15.  
  16.     $("#btnAdicionar").click(function () {
  17.         localStorage.setItem("nome", ($("#nome").val()));
  18.         localStorage.setItem("dificuldade", ($("#dificuldade").val()));
  19.         localStorage.setItem("categoria", ($("#categoria").val()));
  20.         document.location.href = "Jogo.html";
  21.  
  22.  
  23.  
  24.     });
  25.  
  26.     if ($("body").hasClass("jogo") == true) {
  27.  
  28.         var dif = localStorage.getItem("dificuldade");
  29.         var cat = localStorage.getItem("categoria");
  30.         $("#nomebuscar").html(localStorage.getItem("nome"));
  31.         $("#difibuscar").html(localStorage.getItem("dificuldade"));
  32.         switch (cat) {
  33.             case '22':
  34.                 $("#catbuscar").html("<p>Geografia</p>");
  35.                 break;
  36.             case '17':
  37.                 $("#catbuscar").html("<p>Ciências</p>");
  38.                 break;
  39.             case '23':
  40.                 $("#catbuscar").html("<p>História</p>")
  41.                 break
  42.         }
  43.  
  44.         defenirLink(dif,cat);
  45.  
  46.     }
  47.  
  48.     function defenirLink(dif,cat) {
  49.         var link = "https://opentdb.com/api.php?amount=10&category="+cat+"&difficulty="+dif+"&type=multiple";
  50.         getJSONLink(link);
  51.  
  52.     }
  53.  
  54.     function getJSONLink(link) {
  55.         $.getJSON(link, function (data) {
  56.         a = data.results;
  57.  
  58.         comecarPerguntas(0);
  59.  
  60.  
  61.         });
  62.     }
  63.  
  64.     function comecarPerguntas() {
  65.         $("#perguntas").html("<h2>"+ a[nr_pergunta].question +"</h2>");
  66.  
  67.  
  68.  
  69.             var posi_random = Math.floor((Math.random() * 4) + 1);
  70.             var erradas=0;
  71.  
  72.             for(var i = 1; i<=4;i++){
  73.                 if(posi_random == i){
  74.                     $("#respostas").html("<button>"+ a[nr_pergunta].correct_answer +"</button>");
  75.                 }else{
  76.                     $("#respostas").html("<button>" + a[nr_pergunta].incorrect_answers[erradas] + "</button>");
  77.                     erradas += 1;
  78.                 }
  79.             }
  80.         $("#jogar").innerHTML("<button id='btcontinuar'></button> <button id='btfavoritos'></button> ");
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.     }
  90.  
  91.     $("#btncontinuar").click(function(nr_pergunta){
  92.         if ((nr_pergunta +1) == 10){
  93.             pontuacao();
  94.         }
  95.         else{
  96.            nr_pergunta ++;
  97.            comecar_Perguntas(nr_perguntas);
  98.  
  99.  
  100.         }
  101.  
  102.     });
  103.  
  104.     function pontuacao(){
  105.  
  106.     }
  107. });
Advertisement
Add Comment
Please, Sign In to add comment