Pārlūkot izejas kodu

Merge branch 'master' of http://120.78.169.79:3000/zhengxiaoyu/datiGame

郑晓宇 6 gadi atpakaļ
vecāks
revīzija
abea1768d7
2 mainītis faili ar 40 papildinājumiem un 4 dzēšanām
  1. 2 2
      public/h5/datigame/index.html
  2. 38 2
      public/h5/datigame/js/common.js

+ 2 - 2
public/h5/datigame/index.html

@@ -93,8 +93,8 @@
       <div class="result">
         <span class="icon top-icon success" id="Jresult"></span>
         <span class="live" id="Jlastmsg">初级玩家</span>
-        <a href="./Index"><span class="btn-3 btn btn1" data-href="./Index">再来一局</span></a>
-        <span class="btn-3 btn btn2" data-href="./Index">查看等级</span>
+         <span class="btn-3 btn btn1" id="Jagain"  >再来一局</span> 
+        <!-- <span class="btn-3 btn btn2" data-href="./Index">查看等级</span> -->
       </div>
 
     </div>

+ 38 - 2
public/h5/datigame/js/common.js

@@ -73,8 +73,33 @@ common={
         if(data.info.user.user_id!=this.userInfo.user_id){
         	 $("#py2_avatar").html('<img src="' + data.info.user.avatar+ '" class="layui-circle">');
             $("#py2_username").html(data.info.user.name);
+            _this.data.playerId=data.info.user.user_id;
      }
  		 
+ 	},round_end:function(data){
+ 		var _this=this;
+ 		// if(data.info.anwser==_this.data.option_id){
+ 		// 	$(".cur_answer").addClass("cur_true");
+   //        }
+          
+          for (var i = 0; i < data.info.players_answer.length; i++) {
+          	if(data.info.players_answer[i].user_id==_this.userInfo.playerId){
+          		//对方的答案id
+          		_this.data.player_answerId=data.info.players_answer[i].question_id;
+          	}
+          }
+          $("#question .item").each(function(){
+          	if($(this).attr("option_id")==data.info.anwser){
+          		$(this).addClass("cur_true");
+          	}
+          	if($(this).attr("option_id")==_this.data.player_answerId){
+          		//对方答案
+          		$(this).addClass("player_cur");
+          	}
+           
+          })
+
+          
  	},onSocket:function(e){
  		var data=JSON.parse(e.data);
  			var _this=this;
@@ -94,8 +119,16 @@ common={
           _this.loadQuestion(data);
           break;
           case 'round_end':
+          _this.round_end(data);
           console.log("答题结束");
           break;
+          case "answer":
+          if(_this.userInfo.user_id==data.user_id){
+          	_this.increment($("#py1_score"),data.score);
+          }else if(_this.data.playerId==data.user_id){
+          	_this.increment($("#py2_score"),data.score);
+          }
+          break;
           case 'game_end':
           $(".g-doc .g-inner").addClass("end");
           $("#Jvs").hide();
@@ -124,9 +157,9 @@ common={
  	},loadQuestion(responsedata) {
         console.log(responsedata);
        
-        var _this=this;
+    var _this=this;
         _this.data.isAnswer=false;
-       _this.data.question_id= responsedata.info.question.question_id;
+        _this.data.question_id= responsedata.info.question.question_id;
         $("#Jqtitle").html(responsedata.info.question.title );
         var question="";
         var answers = responsedata.info.options
@@ -162,6 +195,9 @@ common={
  		$("#start_game").on("touchend",function(){
  			 _this.startGame();
  		})
+ 		$("#Jagain").on("touchend",function(){
+ 			 window.location.href=window.location.href;
+ 		})
  		
  		
  	},increment:function(bdclass,num){