我正在使用mySound播放声音,具体取决于是否满足某个条件。即使条件不满足,我也会遇到声音相互影响的问题。这是我的代码有什么想法吗?
Game.countAnimals = function(playerGo) {
var count = {bulls:0, cows:0};
Game.counter = 1;
for (var i = 0; i < playerGo.length; i++) {
var digPresent = playerGo.indexOf(Game.score[i]);
if (playerGo[i] == Game.score[i]) {
count.bulls++;
}
else if (digPresent>=0) {
count.cows++;
}
Game.counter++
if (count.bulls === playerGo.length && Game.counter < 7){
mySound2 = new Audio("sounds/Freedom%20Tastes%20Good.mp3");
mySound2.play();
}
else if (count.bulls !== playerGo.length && Game.counter < 7) {
mySound1 = new Audio("sounds/Ass%20is%20dead.mp3");
mySound1.play();
}
else if (Game.counter > 7 ){
mySound = new Audio("sounds/Kill%20You%20Dog.mp3");
mySound.play();
}
答案 0 :(得分:0)
在播放新声音之前,您应该停止所有其他声音。此外,在需要时,不要在函数中实例化声音 - 您只有三个声音,因此在页面加载时,在函数外部实例化它们。
所以固定的代码片应该是这样的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct data{
int testone;
int testtwo;
}data;
struct data _dataStore[25];
int dataCount = 0;
int addData(){
printf("\n\t\t\tPacket Source - ");
scanf("%d", &_dataStore[dataCount].testone);
printf("\t\t\tPacket Destination - ");
scanf("%d", &_dataStore[dataCount].testtwo);
system("CLS");
return 0;
}
void listData(){
int i = 0;
for (i = 0; i < dataCount; i++){
printf("data stored - %d: ",dataCount);
printf("%d___%d \n", _dataStore[i].testone,_dataStore[i].testtwo);
}
}
int main()
{
char choice;
do{
printf("\t\t\t Counter - %i", dataCount+1);
printf("\n\t\t\t1 - Add data. \n");
printf("\t\t\t2 - List data. \n");
printf("\n\t\t\tEnter your choice - ");
fflush(stdin);
choice = getchar();
getchar();
switch(choice){
case '1':
addData();
dataCount++;
system("CLS");
break;
case '2':
system("CLS");
listData();
break;
case '5':
printf("Will exit...");
break;
default:
printf("Invalid input \n");
break;
}
}while (choice != '5');
return 0;
}