php - jquery skip a block -
i have jquery game can view here link text
the game starts entering number in text field. click play button.
after clicking play button set of square appear each rotating random numbers, click on square has number build score, miss 3 times , done.
i added game site, can view here link text
the problem i'm having site members keep cursor on 1 box , wait number appear in 1 box. ruins game. there way make can't click on same box more once in row. they'll have go click box before can come one.
here's complete script
var hitcount = 0, misscount = 0; function isnumeric(n) { return !isnan(n); } $("#getit").click(function() { var hitcount = 0, misscount = 0; $('#hitcount').text(0); $('#misscount').text(0); $('#message').hide(100); var li = [], intervals = 0, n = parseint($('#mynumber').val()); var intervalid = -1; 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 />').appendto('#randomnumber')); } $('#randomnumber').delegate("li", "click", function() { var $this = $(this); if (!$this.hasclass('clicked')) { if (parseint($this.text(), 10) === n) { $this.addclass('correct'); $('#hitcount').text(++hitcount); } else { $this.addclass('wrong'); $('#misscount').text(++misscount); } //new code if misscount > 3 stop game , save value if(misscount>=<?php echo $limit ?>){ clearinterval(intervalid); $('#randomnumber').undelegate("li", "click"); // use ajax request save values $.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; });
have tried using .one()
bind click events, instead of .click()
? here's documentation it: http://api.jquery.com/one/
if bind click event .one()
ensure function triggered once. then, inside function, rebind events other boxes, ensuring have click box before click same 1 again.
alternately:
use combination of .hover()
, settimeout()
(and possibly hoverintent) disable box when user hovers mouse on long.
edit
have @ modified version of jsfiddle: http://jsfiddle.net/ender/9ffta/
clicking on same box twice in row disallowed. can use guide.
Comments
Post a Comment