game.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. const baseUrl = 'http://face3d.4dage.com:8102';
  2. var questionsData =[];
  3. var currData = [];
  4. var correctnum = 0;
  5. var currnum = 1;
  6. function getQuestionsData() {
  7. return new Promise (function(resolve,reject){
  8. $.ajax({
  9. url:baseUrl + '/api/web/list',
  10. type: 'POST',
  11. success: function(res) {
  12. resolve(res.data)
  13. },
  14. error: function(err) {
  15. console.log(err)
  16. }
  17. })
  18. })
  19. }
  20. function updateQuestion() {
  21. console.log(currData);
  22. var html = ` <p class="question fontLiSu colorc"><span class="num">${currnum}</span>.${currData?currData.title:''}</p>
  23. <div class="answer fontLiSu colorc">
  24. <ul id="options" >
  25. ${
  26. currData.answers.map(item => {
  27. return `<li class="li${currnum}" data-correct="${item.correct}">${item.content}</li>`
  28. }).join('')
  29. }
  30. </ul>
  31. </div>`;
  32. $(".topic").html(html);
  33. }
  34. $("#gui-modes-backIndex").click(function() {
  35. location.reload();
  36. })
  37. $("#gui-modes-quiz").click(function() {
  38. $("#game").show();
  39. })
  40. $("#closeGame").click(function() {
  41. currnum = 1;
  42. correctnum = 0;
  43. $(".process").hide();
  44. $(".start").show();
  45. $("#game").hide();
  46. })
  47. $("#start_btn").click(function() {
  48. currnum = 1;
  49. correctnum = 0;
  50. getQuestionsData().then(function(v) {
  51. console.log(v)
  52. questionsData = v.filter(function(item){return item.type=='1'}) ;
  53. currData= questionsData[currnum-1<0?0:currnum-1];
  54. console.log(currData)
  55. $("#start_page").hide();
  56. $("#process_page").show();
  57. updateQuestion();
  58. answer();
  59. })
  60. })
  61. $("#next_btn").click(function() {
  62. console.log(currnum,correctnum)
  63. if(currnum==10&&correctnum<7) {
  64. $("#process_page").hide();
  65. $(".again").show();
  66. }else if(currnum==10&&correctnum>=7) {
  67. $("#process_page").hide();
  68. $(".success").show();
  69. }else {
  70. currnum ++;
  71. currData= questionsData[currnum-1]
  72. updateQuestion();
  73. answer();
  74. }
  75. })
  76. var params = JSON.stringify({
  77. "pageNum": 1,
  78. "pageSize": 1,
  79. "searchKey": "",
  80. "type": 1
  81. })
  82. function answer () {
  83. $(".topic").one('click','li',function(item){
  84. flag= true;
  85. if($(this).attr("data-correct")==0){
  86. $(this).addClass("wrong");
  87. $("#options li").each(function(i,item) {
  88. if($(item).attr("data-correct")==1){
  89. setTimeout(function(){$(item).addClass("correct")},1000)
  90. }
  91. })
  92. }else {
  93. correctnum = correctnum + 1;
  94. $(this).addClass("correct");
  95. }
  96. if(currnum==10) {
  97. if(correctnum>=7) {
  98. $("#process_page").hide();
  99. $(".success").show();
  100. }else {
  101. $("#process_page").hide();
  102. $(".again").show();
  103. }
  104. }
  105. })
  106. }
  107. $(".again-btn").click(function() {
  108. initData();
  109. getQuestionsData().then(function(v) {
  110. console.log(v)
  111. questionsData = v ;
  112. currData= questionsData[currnum-1];
  113. $("#start_page").hide();
  114. $("#process_page").show();
  115. updateQuestion();
  116. answer();
  117. })
  118. })
  119. $(".over-btn").click(function() {
  120. initData()
  121. $("#game").hide();
  122. })
  123. function initData() {
  124. questionsData =[];
  125. currData = [];
  126. correctnum = 0;
  127. currnum = 1;
  128. $(".process").hide();
  129. $(".start").show();
  130. }
  131. $('html').click(function(){
  132. $("#guide").hide();
  133. })