jQuery游戏循环逻辑 [英] jquery game looping logic

查看:102
本文介绍了jQuery游戏循环逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我编写此代码的每个人都选择一个如图所示的随机值,然后向该特定元素添加一个类.现在,当用户单击该元素时,添加的类将被删除(分数计数器增加"1"),程序返回到开始并选择一个随机数并分配该类.这段代码已经写在下面,但是我无法循环播放游戏.用户单击forst元素后,整个机制将无法很好地重复,分数也不会增加.我该怎么办?



Hey everyone I wrote this code this picks a random value like shown and then accordinly adds a class to that specific element. Now when the user clicks that element the class that was added gets removed (the score counter increases by ''1'') and the program goes back to the start and picking a random number and assigning the class. The code for this has been written below, but I am not able to loop loop the game. After the user click the forst element the whole mechanism does not repeat well and nor does the score increase. What should I do?



$(document).ready(function start(){

  var items = Array(11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44);
  var random = items[Math.floor(Math.random()*items.length)];
  $('.c'+random).addClass('mole');


	$("body").click(function(e) {
    	    if ($(e.target).hasClass("sq-color")) 
        	{ 
            	if ($(e.target).hasClass("mole")) 
        		{ 
            		hit.playclip();
            		$('.c'+random).removeClass('mole');
            		
            		var scoreCounter = $("b[id=show-score]").html();
                    var updateScore = eval(scoreCounter)+ eval(1);
                    $("b[id=show-score]").html(updateScore);
            		
        		}	 
        		else
        		{
            		alert("MISS");
            	}	
        	} 
        
    	});




});


粗体已删除

推荐答案

(文档).ready(功能 start(){ var 项目= 数组( 11 12 13 14 21 22 23 31 33 41 42 43 44 ); var random = items [数学 .floor(数学 .random()* items.length)];
(document).ready(function start(){ var items = Array(11,12,13,14,21,22,23,24,31,32,33,34,41,42,43,44); var random = items[Math.floor(Math.random()*items.length)];


(' .c' + random).addClass(' 摩尔');
('.c'+random).addClass('mole');


(" ).click(如果(
("body").click(function(e) { if (


这篇关于jQuery游戏循环逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆