-1
我正在一個西蒙遊戲,我認爲我比較接近結束(耶!),我似乎被卡住了一個問題,雖然。在玩家匹配simon的第一步之後,它會移動到下一輪,然後數組將被填充第二步。然後你可以匹配第二步,並且也可以正確迭代。但我認爲這是第二次射擊,然後通常是錯誤的,然後讓玩家陣列作爲最後一招而不是重置。儘管使用關閉功能點擊,可能導致陣列問題
我該如何確保按鈕只按下一次,以及如何正確地重置播放器陣列?
function playerInput(simon, player, j){
while (j < simon.length)
{
console.log(j);
if(simon[j] === player[j])
{
console.log("player pressed the correct button");
j++;
// potentially not working off function
$(".simon-button").off().on('click', function() {
// stops multiple executions
});
buttons(simon, j, player);
}
else
{
if(strict === true)
{
reset();
return;
}
else
{
console.log("player pressed the wrong button");
// seems to be screwing up here when it's wrong
// but not when used to reset player when it's right
player = [];
repeatMoves(player);
return;
}
}
}
if(j >= simon.length && simon.length < 20)
{
j = 0;
player = [];
newMove(player);
}
else
{
alert("You win!!!");
successSound.play();
reset();
}
}
function buttons(simon, j, player){
green.css('cursor', 'pointer');
red.css('cursor', 'pointer');
blue.css('cursor', 'pointer');
yellow.css('cursor', 'pointer');
$(".simon-button").click(function(){
if($(this).hasClass("green-button"))
{
player.push(greenPushed());
playerInput(simon, player, j);
}
else if($(this).hasClass("red-button"))
{
player.push(redPushed());
playerInput(simon, player, j);
}
else if($(this).hasClass("blue-button"))
{
player.push(bluePushed());
playerInput(simon, player, j);
}
else if($(this).hasClass("yellow-button"))
{
player.push(yellowPushed());
playerInput(simon, player, j);
}
console.log(player);
console.log(simon);
});
}
https://jsfiddle.net/uoyg2jx9/1/
我忘了提,使在空按鈕的小提琴作品點擊開始按鈕,然後。
謝謝,實際上幫了很多。現在它的越野車,但至少它運行2-3。 –