jquery - disable click on hover -


i have jquery game members keep finding ways win. it's numbers game here link text.

i've made game can't play on firefox, don't know if other browsers have same cheat tools firefox.

1st problem had gamers keep mouse on 1 box till number showed they'd click it. fix (with genius on stackoverflow) made can't click same box twice in row. it's same problem, they'll move box , keep mouse till see number. need make if on over box more x number of seconds won't able click on box.

a count down timer may trick though , eliminate hover script. please ever 1 can. here's script.

    var hitcount = 0, misscount = 0;  function isnumeric(n) { return !isnan(n); }  $("#getit").click(function() { var hitcount = 0, misscount = 0; $('#misscount').text(0); $('#hitcount').text(0); $('#message').hide(100);         $('#randomnumber').empty(); $('#randomnumber').show(300);        var li = [],     intervals = 0,     n = parseint($('#mynumber').val());  if (isnumeric(n)) {    intervalid= setinterval(function() {         li[intervals++ % li.length].text(math.random() > .1 ? math.floor(math.random() * (10 + n) + (n / 2)) : n).attr('class', '')    ;     }, <?php echo $time ?>); }  $('#randomnumber').empty();  (var = 0; < 7; i++) {     li.push($('<li />').one('click', function() {         boxclick.call(this, n);     }).appendto('#randomnumber')); }   function boxclick(n) { var $this = $(this); $('#randomnumber li').unbind().one('click', function() {         boxclick.call(this,n); }); $this.unbind();  if (!$this.hasclass('clicked')) {     if (parseint($this.text(), 10) === n) {         $this.addclass('correct');         $('#hitcount').text(++hitcount);     } else {         $this.addclass('wrong');         $('#misscount').text(++misscount);     } }             if(misscount==<?php echo $limit ?>){                clearinterval(intervalid);                $('#randomnumber').hide(300);                  $.ajax({ type : 'post', url : 'fbhighscore_hwnd.php', datatype : 'json', data: { tgameid: $('#tgameid').val(),mynumber: $('#mynumber').val(),totalhits: hitcount }, success : function(data){ $('#waiting').hide(500); $('#message').removeclass().addclass((data.error === true) ? 'error' : 'success') .text(data.msg).show(500); if (data.error === true) $('#loginform').show(500); else $('#send').hide(500);        }, error : function(xmlhttprequest, textstatus, errorthrown) { $('#waiting').hide(500); $('#message').removeclass().addclass('error') .text('there error.').show(500); $('#loginform').show(500); } });              }   $this.addclass('clicked'); } return false; }); 

you can remember when stared hovering. using simplified example of span id "container" containing spans user click on:

jquery(function($) {    var container, n;   var hover_threshold = 1000; // milliseconds    // build grid   container = $('#container');   (n = 0; n < 16; ++n) {     $("<span>0</span>").appendto(container).data("hoverstart", 0);   }    // watch hovers , clicks on elements   container.find('span')     .hover(starthover, stophover)     .click(handleclick);    // @ hover start, remember when started   function starthover() {     $(this).data("hoverstart", new date().gettime());   }    // @ hover end, clear hover thingy   function stophover() {     $(this).data("hoverstart", 0);   }    // on click, check how long they've been hovering   function handleclick() {     var $this, starthover;      $this = $(this);     starthover = $this.data("hoverstart");      // hovering long?     if (starthover != 0         && (new date().gettime() - starthover) > hover_threshold) {       // yes       $this.css("color", "red");       settimeout(function() {         $this.css("color", "");       }, 500);     }     else {       // no, allow click       $this.html(parseint($this.html(), 10) + 1);     }   } });​ 

live example

or can more complex (but proactive) thing timers:

jquery(function($) {    var container, n;   var hover_threshold = 1000; // milliseconds    // build grid   container = $('#container');   (n = 0; n < 16; ++n) {     $("<span>0</span>").appendto(container).data("hovertimer", 0);   }    // watch hovers , clicks on elements   container.find('span')     .hover(starthover, stophover)     .click(handleclick);    // @ hover start, start timer   function starthover() {     var $this = $(this);     $this.data("hovertimer", settimeout(function() {       $this.addclass("disabled");     }, hover_threshold));   }    // @ hover end, clear timer   function stophover() {     var $this, timer;      $this = $(this);     $this.removeclass("disabled"); // may or may not have     timer = $this.data("hovertimer");     if (timer != 0) {       cleartimeout(timer);       $this.data("hovertimer", 0);     }   }    // on click, check how long they've been hovering   function handleclick() {     var $this;      $this = $(this);      // hovering long?     if ($this.hasclass("disabled")) {       // yes, disallow click     }     else {       // no, allow click       $this.html(parseint($this.html(), 10) + 1);       // if want reset hover timer on click:       stophover.call(this);       starthover.call(this);     }   } });​ 

live example

but again, said in comment, can't trust any data sent client sort of thing, there many tools debugging web applications (which great thing!) or faking http messages. in case, don't think it's possible differentiate gifted player gifted faker (ham-handed fakers can figure out data).


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -