gpt4 book ai didi

javascript - 向文本序列添加计数器

转载 作者:太空宇宙 更新时间:2023-11-04 12:40:40 25 4
gpt4 key购买 nike

目前我正在开发一款游戏,我正在使用 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);
},

任何帮助都会很棒

最佳答案

只需更改输出文本的行:

$(".TextBox").children(":first").html('<b>' + (index + 1) + ":" +that.colors[val-1]+'</b>');

更新 fiddle :http://jsfiddle.net/uusL7hch/18/

关于javascript - 向文本序列添加计数器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26909862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com