Javascript 向文本序列添加计数器
目前我正在开发一款游戏,我正在使用JavaScript进行游戏 其中一个功能允许用户查看他们必须输入的序列(打印出他们必须单击的颜色) 但问题是有时它们必须击中同一个圆圈两次等等,这对用户来说并不清楚 所以我想知道是否有可能在序列中添加一个计数器来显示一些简单的东西,比如 1.红色 2.红色 3.蓝色 所以他们可以看到它需要第二个红色等等 这里有一个jsfiddle,您可以理解我的意思 JavaScript文件只缩减到显示颜色名称的代码所在的部分Javascript 向文本序列添加计数器,javascript,html,css,counter,Javascript,Html,Css,Counter,目前我正在开发一款游戏,我正在使用JavaScript进行游戏 其中一个功能允许用户查看他们必须输入的序列(打印出他们必须单击的颜色) 但问题是有时它们必须击中同一个圆圈两次等等,这对用户来说并不清楚 所以我想知道是否有可能在序列中添加一个计数器来显示一些简单的东西,比如 1.红色 2.红色 3.蓝色 所以他们可以看到它需要第二个红色等等 这里有一个jsfiddle,您可以理解我的意思 JavaScript文件只缩减到显示颜色名称的代码所在的部分 $.each(this.genS
$.each(this.genSequence, function (index, val) { //iterate over each value in the generated array
timerCount = index;
setTimeout(function () {
that.flash($(that.shape + val), 1, 300, val);
if ($("#text").is(":checked")) {//Check Box Function
$(".TextBox").children(":first").html('<b>' + that.colors[val - 1] + '</b>');
}
}, 500 * index * that.difficulty); // multiply timeout by how many items in the array so that they play sequentially and multiply by the difficulty modifier
});
// Wait to start timer until full sequence is displayed
setTimeout(function () {
that.timerInterval = setInterval(function () {
that.countDown()
}, 100)
setTimeout(function () {
$(".TextBox").children(":first").html('');
}, 500);
}, 500 * timerCount * that.difficulty);
},
$.each(this.genSequence,function(index,val){//迭代生成的数组中的每个值
timerCount=索引;
setTimeout(函数(){
flash($(that.shape+val),1300,val);
if($(“#text”).is(“:checked”){//复选框函数
$(“.TextBox”).children(“:first”).html(“”+that.colors[val-1]+“”);
}
},500*索引*那个。难度);//将超时乘以数组中的项目数,以便它们按顺序播放,然后乘以难度修饰符
});
//等待启动计时器,直到显示完整序列
setTimeout(函数(){
that.timerInterval=setInterval(函数(){
那倒计时
}, 100)
setTimeout(函数(){
$(“.TextBox”).children(“:first”).html(“”);
}, 500);
},500*timer count*that.难度);
},
任何帮助都很好您需要在数据列表中定义css个人标记:
ol#your_list_name {
list-style-type:decimal;
}
只需更改输出文本的行:
$(".TextBox").children(":first").html('<b>' + (index + 1) + ":" +that.colors[val-1]+'</b>');
$(“.TextBox”).children(“:first”).html(“”+(index+1)+:“+that.colors[val-1]+”);
更新的fiddle:你能把你的代码缩短到相关的代码行吗?@GottliebNotschnabel代码缩短到无法工作的点,因为它正在打印javascript文件,我需要每个sequencePerfect都有一个计数器。非常简单,我已经被困了大约一个小时,谢谢你的帮助