【发布时间】:2014-11-13 13:20:08
【问题描述】:
目前我正在开发一个游戏,我正在使用 JavaScript 进行游戏
其中一个功能允许用户查看他们必须输入的序列(它会打印出他们必须点击的颜色)
但问题是有时他们必须打同一个圆圈两次等,这对用户来说不是很清楚。
所以我想知道是否可以在序列中添加一个计数器来显示像
这样简单的东西1.红色
2.红色
3.蓝色
所以他们可以看到它想要第二个红色等
这是一个 jsfiddle,所以你可以明白我的意思 http://jsfiddle.net/uusL7hch/17/
JavaScript 文件只缩减到显示颜色名称的代码所在的部分
$.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);
},
任何帮助都会很棒
【问题讨论】:
-
能否将您的代码缩短为相关的代码行?
-
@GottliebNotschnabel 代码减少让你明白这一点
标签: javascript html css counter