我制作了一款名为Blitz的游戏技巧。其功能是你在6秒内击中你的对手3次。javascript:我的声音只播放一次?
我在技巧中添加了声音文件,因此您可以听到提示,因此您不必读取文本日志。我遇到的问题是,当我击中对手2次或更多次时,声音文件只播放一次,而不是两次。
例如:This Works - Hit,Miss,Hit。 例如:这不起作用 - 打,打(没有声音),小姐(声音)
为什么它跳过或不玩?
// BLITZ SKILL
document.getElementById("blitz").addEventListener('click', function() {
atbReset();
DB();
RET();
window.setTimeout(function() { blitzskill() }, 1000);
window.setTimeout(function() { blitzskill() }, 2000);
window.setTimeout(function() { blitzskill() }, 3000);
});
function blitzskill(){
var criticalRoll = Math.floor(Math.random() * 100 + 1);
var precisionRoll = Math.floor(Math.random() * cs.precision + 1);
var npcParryRoll = Math.floor(Math.random() * ds.parry + 1);
var damage = Math.floor(Math.random() * cs.strength * 1);
if (character.energy <= 4) {
addMessage("Not enough energy!")
return;
}
if (precisionRoll < npcParryRoll) {
addMessage("The Dragon evaded your attack!");
character.energy -= 5;
miss.play(); // PLAY MISS SOUND
}
else if (damage - ds.armor <= 0) {
character.energy -= 5;
addMessage("Your opponents armor withstood your attack!");
armor.play(); // PLAY MISS/ARMOR SOUND
}
else if (cs.critical >= criticalRoll) {
damage *= 2;
damage -= ds.armor;
dragon.hp -= damage;
character.energy -= 5;
document.getElementById("npchp").innerHTML = dragon.hp;
addMessage("Critical Strike! Dragon suffers " + damage + " hp!")
swoosh.play(); // PLAY HIT SOUND
}
else {
dragon.hp -= damage;
damage -= ds.armor;
document.getElementById("npchp").innerHTML = dragon.hp;
addMessage("You hit the dragon for " + damage + " hp!");
character.energy -= 5;
swoosh.play(); // PLAY HIT SOUND
}
document.getElementById("energy").innerHTML = character.energy;
};
你在哪里得到旋风 - 你可以设置一个小提琴无你的游戏逻辑代码 – megawac
swoosh就是我用来击打对手的声音文件。我将setTimeOut加到了每个2.5秒,并修复了它,所以它与已经在第二次播放的声音文件有关。 – Shawn
嗯..那里有'setTimeout'在那里做什么?点击时,你真的必须打三次“blitzskill”吗? – aIKid