home *** CD-ROM | disk | FTP | other *** search
/ Orthodox Religion Class (2nd Semester) / ReligieCls1Sem2.iso / js / games / GamesSingleTick.js < prev    next >
Encoding:
JavaScript  |  2015-03-23  |  2.9 KB  |  82 lines

  1.  
  2. function GamesSingleTick(config){
  3.     this.config = config;
  4. }
  5.  
  6. GamesSingleTick.prototype.resetLevel = function() {
  7.     $("*[data-A-type='tick']").css("display","none");
  8. };
  9.  
  10. GamesSingleTick.prototype.checkIfFinish = function() {
  11.     var no = 0;
  12.     $("*[data-A-type='tick']").each(function(key,value){
  13.         if(($(this)).css("display")!="none"){
  14.                 no++;
  15.         }
  16.     });
  17.     return (no==0);
  18. };
  19.  
  20. GamesSingleTick.prototype.getCorrectAnswer = function(){
  21.     $("*[data-A-type='tick']").css("display","none");
  22.     for (var j = 0; j < this.config.objects.length; j++) {
  23.         if(this.config.objects[j].response==1)
  24.             $("#Atick"+j).toggle();
  25.     }
  26. };
  27.  
  28. GamesSingleTick.prototype.checkSingleResultIndex = function(index){
  29.     console.log($("#Atick"+index).css("display"));
  30.     return ((this.config.objects[index].response==1) && ($("#Atick"+index).css("display")!="none" ) ||
  31.                (this.config.objects[index].response==0) && ($("#Atick"+index).css("display")=="none" ));
  32. };
  33.  
  34. GamesSingleTick.prototype.getCheckLength = function(){
  35.     return this.config.objects.length;
  36. };
  37.  
  38. GamesSingleTick.prototype.getResult = function(){
  39.     return this.config.result;
  40. };
  41.  
  42. GamesSingleTick.prototype.initialize = function(){
  43.     var config = this.config;
  44.     if(this.config.fundal!=null){
  45.         $("#gameStage").append("<img id='fundal'>");
  46.         util.setImageStyle($("#fundal"), this.config.fundal);
  47.     }
  48.         
  49.     for (var i = 0; i < this.config.objects.length; i++) {
  50.         $("#gameStage").append(
  51.                 "<div id='AidInput"+i+"' data-A-index='"+i+"' "+
  52.                     " onclick='"+((!isRepeatActive)?"return false":"")+ "'" +
  53.                     " style='z-index:2000;position:absolute;cursor:pointer;" +
  54.                     ((this.config.displayInput===undefined)?"border-style:solid;outline: none;  border-color:  #A77649; " +
  55.                             " box-shadow: 0 0 10px  #A77649;" : "")+
  56.                     "top:"+this.config.inputs[i].top+"px;" +
  57.                     "left:"+this.config.inputs[i].left+"px;" +
  58.                     "width:"+this.config.inputs[i].width+"px;" +
  59.                     "height:"+this.config.inputs[i].height+"px;" +
  60.                     "background:transparent;'></div>" +//border:1px solid;border-color:red
  61.                     "" +
  62.                     "<img id='Atick"+i+"' data-A-type='tick' style='position:absolute;display:none;" +//display:none;
  63.                      "top:"+(this.config.objects[i].top+this.config.imgTick.top)+"px;" +
  64.                      "left:"+(this.config.objects[i].left+this.config.imgTick.left)+"px;" +
  65.                      "' src='"+((this.config.imgTick===undefined)?imagesCommon.tick:this.config.imgTick.src)+"' alt='' " +
  66.                      "width='"+this.config.objects[i].width+"px' height='"+this.config.objects[i].height+"px'/>");
  67.             util.setCheckImage(this.config.nameGame, this.config.objects[i], i ,25,0);
  68.     }
  69.     
  70.     
  71.     
  72.     $("*[data-A-index]").click(function() {
  73.         if(!isActive)
  74.             return false;
  75.         $("#Atick"+$(this).attr("data-A-index")).toggle();
  76.     });
  77.         $("#gameStage").click(function(e) {
  78.     console.log("left:"+Math.round((e.pageX-$("#gameStage").offset().left)/scale/3)+",top:"+
  79.     Math.round((e.pageY-$("#gameStage").offset().top)/scale/3)+"");});    
  80. };
  81.  
  82.