gpt4 book ai didi

javascript - JQuery/JS : Progressive cycling through array to show picture sequence, 与用户的输入比较

转载 作者:行者123 更新时间:2023-12-01 05:48:54 25 4
gpt4 key购买 nike

好吧,这有点复杂,至少对我来说是这样。起初,我正在制作 Simon 的 Javascript 游戏。一切都很顺利,直到我意识到我以前从未扮演过西蒙。游戏规则发生了变化,我不得不重新编写整个游戏的代码。

我必须在每个玩家轮到之前一次显示序列的一部分,而不是在每个玩家轮到之前显示完整的序列。看来这对我来说是一个大问题。我已经尝试了一切让它正常工作,但现在唯一发生的事情是它给我警报消息(直到player1Turn()警报),直到它变得困惑。这对我来说非常重要,因为它是一个项目。

现在看来代码没有记录玩家的输入。我会尽力发表评论。

        function playButtonSequence(sequence) {
alert("playing sequence");
// "sequence" contains originally generated random array.
// it get shift()ed at end of function. so let game end if it's complete.
if (sequence.length < 1) {
endGame();
}
//sequenceCounter is a global var beginning at 1.
//storedSequence is a slice() of sequence.
//so far, this only shows the first element of the array. Good.
if (sequence.length >= 1) {
var i = 0;
while( i < sequenceCounter ) {
$("#c" + storedSequence[i] + "i").attr("src", "imgs/" + storedSequence[i] + ".png");
$("#snd" + storedSequence[i])[0].play();

setTimeout(function() {
$("#c" + storedSequence[i] + "i").attr("src", "imgs/d" + storedSequence[i] + ".png");
}, gameMode.speed);
i++;
}
}
//shift the sequence for control purposes, iterate sequenceCounter, move onto player1's Turn!
sequence = sequence.shift();
sequenceCounter++;
player1Turn();
}
function player1Turn() {
// Got the alert, we're in, at least. But no sound is played when I click a button (the functions for the buttons worked fine before. the arrays are not being compared. Why?
alert("Es turno del jugador uno!");
player1.active = true;
if (player1.active === false && player1.sequence.length === sequenceCounter.length) {
player2.active = true;
player2Turn();
}
if (player1.active) {
$("#c1i, #c2i, #c3i, #c4i").unbind();
$("#c1i").on("click", function() {
redButton();
player1.sequence.push(1);
player1.active = false;
});
$("#c2i").on("click", function() {
yellowButton();
player1.sequence.push(2);
player1.active = false;
});
$("#c3i").on("click", function() {
blueButton();
player1.sequence.push(3);
player1.active = false;
});
$("#c4i").on("click", function() {
greenButton();
player1.sequence.push(4);
player1.active = false;
});
}
}

最佳答案

查看这个开源版本的 Simon Says 游戏以获取灵感。

https://github.com/kellyk/javascript-simon/

关于javascript - JQuery/JS : Progressive cycling through array to show picture sequence, 与用户的输入比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24226536/

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